Reputation: 1824
I want to match all /admin/* request expect .png, .gif, .js file types. So write this route:
app.all('/admin*', requiresLogin);
But i can't exclude that file types. How can i exclude .png, .gif, .js request from that routing ?
Upvotes: 0
Views: 1570
Reputation: 1763
You could also just set up express to serve your static files so that requests for .png, .gif, .js etc are already completed before this route
// will serve pictures and scripts
app.use(express.static('path/to/png/gif/and/js/files'));
// will not see requests like '/admin/happy.gif'
app.all('/admin', requireLogin);
Upvotes: 1
Reputation: 26667
How about the regex
\/admin[^.]*\.(?!(?:png|gif|js))
will exculde .png, .gif, .js
see how the regex matches at http://regex101.com/r/mW5qZ9/1
\/admin
matches /admin
[^.]*\.
matches anything other than .
followed by .
(?!(?:png|gif|js))
asserts that the regex is not followed by png|gif|js
Upvotes: 2