I have route:
app.get(\'/:id\', routes.action);
It works fine, but I need skip robot.txt
and other (humans ....)
I create rege
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
.
Then the static file (such as robots.txt) will be delivered and these calls will not get through to your routing.
Problem solved ;-).
Internally, the strings that you give to the Express router are just converted into regexes anyway. If you look at the code, you can see that you can just pass a regex directly.
app.get(/^\/[a-z]{0,10}$/, routes.action);
The docs also have examples.
Put the regex in parentheses like this:
app.get('/:id(^[a-z]{0,10}$)', routes.action);
If you need it for multiple routes :
app.routes.get
is an array having all of the get routes. You can change the regex object for the routes you need to change.