Created
August 27, 2012 12:17
-
-
Save spion/3487954 to your computer and use it in GitHub Desktop.
Create a middleware from a list of middlewares.
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
module.exports = function () { | |
var list = arguments; | |
return function (req, res, realNext) { | |
var id = -1; | |
var innerNext = function (err) { | |
if (err) return realNext(err); | |
var nextFn = ++id < list.length - 1 ? innerNext : realNext, | |
mw = list[id]; | |
mw(req, res, nextFn); | |
}; | |
innerNext(); | |
}; | |
}; | |
// usage example: | |
// var middlewarelist = require('connect-list'); | |
// var passportWithDeps = middlewarelist(express.bodyParser(), express.methodOverride(), mySession, passport.initialize(), passport.session()); | |
// somewhere other | |
// app.use('/login', passportWithDeps); // it makes sure they're loaded in the correct order. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment