I am trying to create a middleware that can accept parameters. How can this be done?
example
app.get(\'/hasToBeAdmin\', HasRole(\'Admin\'), function(
Alternatively if you do not have too many cases or if role is NOT a string:
function HasRole(role) {
return function (req, res, next) {
if (role !== req.user.role) res.redirect(/* ... */);
else next();
}
}
var middlware_hasRoleAdmin = HasRole('admin'); // define router only once
app.get('/hasToBeAdmin', middlware_hasRoleAdmin, function (req, res) {
})