我想要以下路线:
// Services without csrf()
router.get('/user/:uid', userRes.findUser, userRes.GETUser);
router.post('/user/:uid', userRes.findUser, userRes.POSTUser);
// Rest of routes, with csrf()
router.use(csrf());
router.post('/user/subscribe', indexRes.POSTSubscribe);
但是这里发生的情况是 POST/user/subscribe
匹配第二条路由。
我一直在阅读Express routes parameter conditions但它展示了如何过滤数字。我想过滤“订阅”路径:
还有机会吗?
最佳答案
您可以使用router.param
:
var staticUserPaths = ['subscribe'];
router.param('uid', function (req, res, next, id) {
if (~staticUserPaths.indexOf(id)) {
next('route');
} else {
next();
}
});
关于node.js - 表达4参数条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26410461/