Created
July 23, 2012 15:41
-
-
Save Enome/3164298 to your computer and use it in GitHub Desktop.
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
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); | |
} |
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
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