Skip to content

Instantly share code, notes, and snippets.

@Enome
Created July 23, 2012 15:41
Show Gist options
  • Save Enome/3164298 to your computer and use it in GitHub Desktop.
Save Enome/3164298 to your computer and use it in GitHub Desktop.
var model = {
name: 'product',
route: [ middleware1, middleware2 ]
};
var model2 = {
name: 'page'
};
function middleware(req, res, next) {
if (model.route) {
return walkSubstack(model.route, req, res, next);
}
res.render(model.name);
}
var walkSubStack = function (stack, req, res, next) {
if (typeof stack === 'function') {
stack = [stack];
}
var walkStack = function (i, err) {
if (err) {
return next(err);
}
if (i >= stack.length) {
return next();
}
stack[i](req, res, walkStack.bind(null, i + 1));
};
walkStack(0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment