I want to ignore all paths of the form /foo/* on my express server. So I want to do
app.get('someRegexThatDoesntMatchFoo/*', routes.index)
I have tried
app.get('/^\(\(.*foo/.*\)\@!.\)*$', routes.index);
but that didnt work-- it doesn't catch all-routes-besides-foo
and apply routes.index
instead i get a CANNOT GET bar
for any /bar
request
Any suggestions?
Thanks!
The first answer was not correct, that's why I post again.
The following regex will match any path except those starting with /foo/
app.get(/^\/([^f]|f[^o]|fo[^o]|foo[^/]).*$/, routes.index);
This solution gets more and more complex as the size of the string increases.
Anyway, looking here for a regex is not the right thing.
When configuring routes, you have always to start with the more special rule and finish with the most general. Like this you would not run in such issues.
You first have to define your route for /foo/*
and after that for all others *
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With