Skip to content

Instantly share code, notes, and snippets.

@caridy
Created March 23, 2013 00:18
Show Gist options
  • Save caridy/5225738 to your computer and use it in GitHub Desktop.
Save caridy/5225738 to your computer and use it in GitHub Desktop.
var m1 = function (req, res, next) {
next();
};
var m2 = function (req, res, next) {
next();
}
var m3 = function (req, res, next) {
next();
// or next(new Error('ops!'));
};
module.exports = function(config) {
return function (req, res, next) {
var all = [m1, m2, m3];
function run () {
var m = all.shift();
if (!m) {
return next();
}
m(req, res, function (err) {
if (err) {
return next(err);
}
run();
});
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment