Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch all route EXCEPT for /login

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 /?

like image 597
clifford.duke Avatar asked Oct 11 '13 07:10

clifford.duke


1 Answers

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) {   ... }); 
like image 121
robertklep Avatar answered Oct 08 '22 15:10

robertklep