expressjs bind all routes except 2 folders?

て烟熏妆下的殇ゞ 提交于 2020-01-03 19:33:49

问题


In expressjs, how do I bind a route to all urls except /static and /fail

For example, it sound bind to:

/users
/books
/books/anything

but not bind to

/static
/fail
/fail/anything
/static/anything

回答1:


If you are saying you want to create one route for everything but /static* then here is the command for creating the GET route:

app.get(/^((?!\/static).)*$/, function(req, res){

    //Do your thing in here...
});



回答2:


My question was just slightly different and this was the best question/answer combo I found so I wanted to share my solution stolen from Clint's answer. If you need like me to restrict from a list of couple of routes like /static and /fail, the following worked for me:

app.get(/^(?!(\/static|\/fail)).*$/, function(req, res, next){

  //Do your thing in here...
});


来源:https://stackoverflow.com/questions/6586197/expressjs-bind-all-routes-except-2-folders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!