Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Nishant-Dwivedi opened this issue Apr 13, 2025 · 2 comments
Labels

Comments

@Nishant-Dwivedi
Copy link

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().

@ShubhamOulkar
Copy link
Member

ShubhamOulkar commented Apr 13, 2025

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

@bjohansebas

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants