Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude a specific path from Express' all()

Tags:

express

I'm using the following to check for privileges on every request to my server:

 app.all('*',users.authCheck);

However, i wish to disable this for one specific request, namely the login route:

app.post('/users/login', users.login);

I know that i could move all my routes into another directory and change to app.all('foobar/*',users.authCheck);

However, i would rather like to exclude one route.

Is this possible?

like image 658
user2422960 Avatar asked May 09 '26 14:05

user2422960


1 Answers

You could simply add a if to your route:

// Somewhere in your app
users.authCheck = function(req, res, next) {
  if (req.url === '/users/login') {
    return;
  }
};

That's not the best solution, however will help you for now.

like image 118
gustavohenke Avatar answered May 11 '26 14:05

gustavohenke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!