Created
July 6, 2014 22:05
-
-
Save aj0strow/b0a1232d2f0df54e1a13 to your computer and use it in GitHub Desktop.
Compose Middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var waterfall = require('async-waterfall') | |
var flatten = require('lodash.flatten') | |
module.exports = compose | |
function compose () { | |
var middlewares = flatten(arguments) | |
function composed (req, res, next) { | |
var callbacks = middlewares.map(function (middleware) { | |
return middleware.bind(middleware, req, res) | |
}) | |
waterfall(callbacks, next) | |
} | |
return composed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment