【发布时间】:2016-04-28 21:10:54
【问题描述】:
问题是路径可能很谨慎;例如,我想支持以下路径:
/chat/auth/test
/chat/auth/add
/chrome/auth/test
/chrome/add
每次 auth 在路径中时,我都希望调用 auth 中间件,对于 chat 和 chrome 我希望它们各自要调用的中间件。
app.js:
// Middleware authentication
var chatAuthenticate = require('./server/middleware/chat-authenticate');
app.use('/chat', chatAuthenticate(addon));
var authAuthentication = require('./server/middleware/auth-authenticate');
app.use('/auth', authAuthentication());
我知道我可以为每个可能的组合添加多个条目到 app.js,例如 /chat/auth 和 /chrome/auth,它根本不会增加复杂性,但我只是好奇它是否可以用通配符或正则表达式解决这个问题:)
【问题讨论】:
-
每个中间件都使用
req, res, next调用。所以如果你想使用另一个中间件就使用next,如果你只需要中间件就不要使用它。
标签: regex node.js express wildcard webhooks