我试图使用一个中间件数组。好吧,更像是函数名和数组的组合。在express.js上使用一组中间件
而是具有:
router.post('/editPassword', validate, changePassword, sendConfirmation);
我想有这样的:
router.post('/editPassword', validate, [changePassword, sendConfirmation]);
这将是这样的:
router.post('/editPassword', validate, doAction);
凡doAction
会是这样的一个数组:
var doAction = [
//equivalent of changePassword
function(req, res, next){
//whatever
next();
},
//equivalent to the previous sendConfirmation
function(req, res, next){
//whatever
}
]
但它似乎失败了,并且在doAction
的第一个函数内返回next()
之后的validate
步骤。
我正在寻找一种方法来简化中间件链接,其中包括一些中间件步骤同名。
你有没有尝试把'验证'在数组以及仅用于测试目的? – Tholle
你能解释一下_“回到'validate'步骤”吗?它是否再次调用该中间件? – robertklep
对不起,我的错。它似乎工作得很好。 我在'next()'之后忘了return语句。所以...现在我想知道,为什么使用组合中间件,那么如果这工作得很好? – Alvaro