ExpressJS route regex

后端 未结 4 1181
别跟我提以往
别跟我提以往 2021-01-11 19:42

I have route:

app.get(\'/:id\', routes.action);

It works fine, but I need skip robot.txt and other (humans ....) I create rege

4条回答
  •  遥遥无期
    2021-01-11 20:14

    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.

提交回复
热议问题