Created
August 4, 2013 01:44
-
-
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.
This file contains hidden or 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
/** | |
* @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