我使用Node和Express进行API REST。是否可以在路由器中添加条件IF状态?就像这样:
.route('/app')
.post(
openPool
, checkToken
, checkCondition //set req.condition = true
(req, res, next) => {
if (req.condition === true){
Controller1
, Controller2
}
next()
}
, sendResponse
);
它不会抛出任何错误,它只是不执行Controller1和Controller2的代码
答案 0 :(得分:1)
如果控制器是功能,你应该这样做:
Controller1(req, res, () => Controller2(req, res, next))`