ExpressJS路由正则表达式 [英] ExpressJS route regex
本文介绍了ExpressJS路由正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有路线:
app.get('/:id', routes.action);
它工作正常,但我需要跳过 robot.txt
和其他(人类....)
我创建正则表达式(仅字符或数字):
It works fine, but I need skip robot.txt
and other (humans ....)
I create regex (only chars or number):
/^[a-z]{0,10}$/
我如何只路由ids,哪些匹配这个正则表达式?
How I can route only ids, which match this regex?
推荐答案
如果你想避免与物理上存在的静态文件匹配的路由,只需将 static
中间件之前调用 app.router
。
If you want to avoid a route matching a static file that exists physically, simply put the static
middleware before the call to the app.router
.
然后静态文件(如robots.txt)将被传递,这些调用将无法通过您的路由。
Then the static file (such as robots.txt) will be delivered and these calls will not get through to your routing.
解决问题; - )。
Problem solved ;-).
这篇关于ExpressJS路由正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文