Eduardo
Eduardo

Reputation: 5933

NodeJS - Express incorrectly executes second route

I have two routes that match the URL http://localhost:8080/app/users/find but I don't want the second one to be executed because the first is more specific.

In the example below how can I prevent the 'did not stop' message of being written?

app.get('/app/users/find', function(req, res, next) {
    console.log('route 1');
    res.end('route 1 return');
    next('stop!');
});

app.all('/:controller?/:action?(/|)', function (req, res, next) {
    console.log('did not stop');
    res.end();
});
  1. Not calling next() - does not work
  2. Calling next(new Error('something')) - does not work
  3. Returning false - does not work
  4. Doing nothing - System hangs

Upvotes: 0

Views: 51

Answers (2)

Eduardo
Eduardo

Reputation: 5933

There were actually two requests happening. The second one was to /favicon.ico

Upvotes: 0

SLaks
SLaks

Reputation: 887195

That's exactly what next() does.

If you don't want to run the next handler, don't call that.

Upvotes: 2

Related Questions