expressjs.com icon indicating copy to clipboard operation
expressjs.com copied to clipboard

Possible error in the logical flow of the middleware sub-stack example provided in the website.

Open Nishant-Dwivedi opened this issue 9 months ago • 2 comments

Description

Image

Expectations

I could be wrong but i think you need to either remove the bang in front of req.headers['x-auth'] or swap next('route') with next().

Nishant-Dwivedi avatar Apr 13 '25 05:04 Nishant-Dwivedi

Hi @Nishant-Dwivedi , thanks for suggesting. I think the current logic is correct though — the ! is intentional because we want to block requests that are missing the x-auth header.

Also, we use next('router') to skip the rest of the router if the header is missing, so it falls through to the 401 handler.

I think we need to improve our documentation on next(). Cc @expressjs/docs-wg

ShubhamOulkar avatar Apr 13 '25 14:04 ShubhamOulkar

Hey @ShubhamOulkar, don't ping the TC when it's not necessary, that's what the documentation group is for. The ping to the TC is for organizational administrative matters.

I'll read this issue later, I have work to do.

bjohansebas avatar Apr 14 '25 15:04 bjohansebas