Express.js is the next middleware level called when the response explicitly ends.

I came across the following behavior:

When I have several middleware installed, the request continues to cascade to the next middleware, although I explicitly end the request with the help res.json()in the previous middleware. Also note that I DO NOT call next()anywhere in the middleware mentioned.

app.use('/v1/status', function (req, res, next) {
    res.json({ status: 'ok' });
});

app.use(function (req, res, next) {
    console.log('I always get called');
});

Is this a "new" behavior? Because for my understanding (and 4x docs) this should not happen.

Any help would be greatly appreciated.

express v4.13.0 on mac osx

+4
source share
1 answer

, @dougwilson. URL, /favicon.ico, .

, , favicon . . , res.json() .

, ! !

+1

Source: https://habr.com/ru/post/1598690/


All Articles