Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle all requests as filter context in Express?

Tags:

express

Checking Express docs I saw this kind of solution below:

app.all('/*', function(req, res) {
    console.log('Intercepting requests...');
});

Its really intercept the request and output on the console the message. The problem is the execution process of the site doesn't stop, the request doesn't ends and seems to be in a kind of loop. There is another way to simulate filters on Express or can't do it right now?

Thanks!

like image 843
Ito Avatar asked Dec 26 '22 11:12

Ito


1 Answers

You have to add next as a parameter to your function and then call it inside when you're done with logging

app.all('/*', function(req, res, next) {
  console.log('Intercepting requests ...');
  next();  // call next() here to move on to next middleware/router
})
like image 180
zemirco Avatar answered Dec 31 '22 10:12

zemirco