gpt4 book ai didi

node.js - 低优先级 Express.js app.get ('/route' );

转载 作者:搜寻专家 更新时间:2023-10-31 22:42:33 24 4
gpt4 key购买 nike

有没有办法注册一个低优先级的 express.js app.get() 调用?

例如,

app.get('*', function(req, res) {});
app.get('/page', function(req, res) {});

有没有一种方法可以在第一次调用时指定较低的优先级,使其位于路由查找的底部,从而允许首先检查后来调用的路径,就好像第一行代码是在之后执行的一样第二行代码?

最佳答案

我刚刚快速浏览了 Express 的源代码,似乎在添加路由时无法设置任何类型的优先级。路由始终按创建顺序匹配。在您的示例中,它将首先尝试匹配 '*',然后是 '/page'

但是,您可以在完成后要求 Express 恢复匹配:

app.get('*', function (req, res, next) {   // run some tests on the request   // ...   // finally, resume matching   next();});

关于node.js - 低优先级 Express.js app.get ('/route' );,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13938927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com