我的 Express 应用程序中有一个路线列表。 我需要对其中一些路线执行特定操作。
例如:
app.get('/xyz', file.xyz);
app.post('/xyz1', file.xyz1);
app.post('/xyz2', file.xyz2);
app.post('/xyz3', file.xyz3);
app.post('/xyz4', file.xyz4);
现在我想对“/xyz2”和“/xyz3”路由执行类似的操作。 我遇到过:
app.all('*', function (request, response, next) {
//some action here
next();
});
我需要传递如下内容:
app.all(['/xyz2','/xyz3'], function (request, response, next) {
//some action here
next();
});
最佳答案
可以使用正则表达式来匹配快速路线。
试试这个:
app.all(/\/xyz[23]/, function (request, response, next) {
//some action here
next();
});
关于node.js - 在 Node Express 的 app.all() 函数中使用一组路由进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31699903/