Skip to content

Instantly share code, notes, and snippets.

@nemtsov
Created August 4, 2013 01:44
Show Gist options
  • Save nemtsov/6148720 to your computer and use it in GitHub Desktop.
Save nemtsov/6148720 to your computer and use it in GitHub Desktop.
Connect middleware used when you need to combine multiple other middleware into one.
/**
* @param {Array} list of middleware to combine
*/
module.exports = function (list) {
return function (req, res, next) {
(function iter(i) {
var mid = list[i]
if (!mid) return next()
mid(req, res, function (err) {
if (err) return next(err)
iter(i+1)
})
}(0))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment