compose-middleware
compose-middleware copied to clipboard
How to use with http.createServer?
This seems to work, but I'm not sure if I'm missing anything (like error handling):
const { compose } = require('compose-middleware')
const { createServer } = require('http')
const middleware = []
const handler = compose(middleware)
const server = createServer((req, res) => {
handler(req, res, () => res.end())
})
Thanks for creating this package @blakeembrey!
@matthewmueller This is fine. You could also use finalhandler like Express/Connect does. Error handling is supported by the four argument syntax and passes it via next(err) (same as Express/Connect also). Would love to use this as reference for updating the README, is that alright?