英文:
Is it possible to use multiple middleware functions for just one express endpoint?
问题
可以,你可以像这样编写带有两个中间件函数(authenticateToken 和 authenticateAdminKey)的代码:
app.post('/api', authenticateToken, authenticateAdminKey, function() {
// ...
});
我知道当你为所有端点使用多个中间件时,类似的方式是可行的(如这里所提到的)。但是我想知道是否可以仅对一个端点实现类似的功能?
英文:
Basically, is it possible to write code like this with two middleware functions (authenticateToken and authenticateAdminKey) ?
app.post('/api', authenticateToken, authenticateAdminKey, function() {
...
}
I know something similar is possible when you're using multiple middleware for all the endpoints (as mentioned here). But I wanted to know if something like this is possible for just one endpoint?
答案1
得分: 4
中间件列表以数组形式传递
app.post('/api', [authenticateToken, authenticateAdminKey], function() {
// ...
}
英文:
middleware list pass in array
app.post('/api', [authenticateToken, authenticateAdminKey], function() {
...
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论