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
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
Share
Improve this question
edited Jun 19, 2017 at 12:27
laser
1,37613 silver badges14 bronze badges
asked Jul 5, 2011 at 16:59
HarryHarry
55.1k76 gold badges187 silver badges270 bronze badges
5
-
Sounds like bad design. Just bind to
users
,books
, etc individually – Raynos Commented Jul 5, 2011 at 18:16 - @Raynos routing happens on the client side. – Harry Commented Jul 5, 2011 at 18:27
- no routing happens on the server. express runs on the server. – Raynos Commented Jul 5, 2011 at 18:35
- @Raynos express serves one document to all. Actual routing happens on the clientside with backbone.js and html5 pushstate. – Harry Commented Jul 5, 2011 at 18:58
- should have mentioned that in the question ;) – Raynos Commented Jul 5, 2011 at 19:11
2 Answers
Reset to default 8If you are saying you want to create one route for everything but /static* then here is the mand for creating the GET route:
app.get(/^((?!\/static).)*$/, function(req, res){
//Do your thing in here...
});
My question was just slightly different and this was the best question/answer bo 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...
});