Created
August 14, 2012 17:25
-
-
Save spion/3351002 to your computer and use it in GitHub Desktop.
connectjs middleware dependencies solution proposal
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) { | |
var nextFn = ++id < list.length - 1 ? innerNext : realNext, | |
mw = list[id]; | |
if (err) mw(err, req, res, nextFn); | |
else 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