[英]Only matching GET and POST routes if a static file doesn't match?
I have this route: app.get('/:a/:b/:c', routes.get);
我有这条路线: app.get('/:a/:b/:c', routes.get);
And this static definition: 而这个静态定义:
app.use('/test', express.static(__dirname + '/test'));
Now, the problem arises when I try to access /test/a/b.js
. 现在,当我尝试访问/test/a/b.js
时出现问题。 Since it matches both paths, routes.get
is triggered. 由于它与两个路径都匹配, routes.get
会触发routes.get
。 How do I prevent this, and only route if a static resource file wouldn't be served otherwise? 如何防止这种情况发生,并且仅在无法提供静态资源文件的情况下才进行路由?
Put app.use(express.static(__dirname + '/test'))
before app.use(app.router)
. 将app.use(express.static(__dirname + '/test'))
app.use(app.router)
之前。
Middleware runs in the order defined in .configure()
. 中间件按照.configure()
定义的顺序运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.