Middleware layer for http
.
$ npm install http-middleware
const mw = require('http-middleware')
const http = require('http')
http.createServer((req, res) => {
const fns = [
(req, res) => res.write('oh yeah!'),
(req, res, next) => {
res.statusCode = 200
next()
}
]
mw(req, res, fns, res.end)
}).listen(1337)
Create a middleware layer that runs an array of middleware functions in
sequence. Middleware functions have a signature of req, res, next
where
next
is optional.
Middleware is typically an array of functions that is run before executing 'business logic'. Function types include authentication, rate limiting, logging and more.
Frameworks are a bundle of opinions. By splitting features off into separate modules (like this middleware module) users can compose their perfect framework. See http-framework for more modules in this spirit.