I am currently writing an API which will require a user to pass an authentication token in the header of each request. Now I know I can create a catchall route say
app.get('/*', function(req,res){ });
but I was wondering how do I make it so that it excludes certain routes such as /login
or /
?
I'm not sure what you want to happen when a user accesses /login
or /
, but you can create separate routes for those; if you declare them before the catch-all, they get first dibs at handling the incoming requests:
app.get('/login', function(req, res) { ... }); app.get('/', function(req, res) { ... }); app.get('*', function(req, res) { ... });
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