Skip to content
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

fix(platform-express) make check for existing middlewares work with Express 5 #14574

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

luddwichr
Copy link
Contributor

Express 5 made the router public API again and renamed the field from app._router to app.router. This broke the detection mechanism whether a middleware named "jsonParser" or "urlencodedParser" is already re or not, because app._router no longer exists.

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • Tests for the changes have been added (for bug fixes / features)
    • the adjusted code seems totally untested. so not sure how to add a simple test. maybe I missed something?
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

The express adapter overwrites existing middlewares called jsonParser and urlencodedParser with its on parsers.

This regression was caused by updating from Express 4 to 5. Express 5 exposes the router via app.router, while Express 4 exposed it via app._router.

Issue Number: N/A - I didn't create an issue yet - let me know if you need that

What is the new behavior?

The express adapter respects existing middlewares called jsonParser and urlencodedParser and stops registering its own parser middleware.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

…with Express 5

Express 5 made the router public API again and renamed the field from app._router to app.router.
This broke the detection mechanism whether a middleware named "jsonParser" or "urlencodedParser"
is already re or not, because app._router no longer exists.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 66d2d166-8df4-4956-b8ca-640d2ca9090c

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 89.702%

Totals Coverage Status
Change from base Build 8ad93cf3-f5a1-4dd6-a743-5980f21f6a8c: 0.0%
Covered Lines: 7108
Relevant Lines: 7924

💛 - Coveralls

@kamilmysliwiec kamilmysliwiec merged commit f061706 into nestjs:master Feb 6, 2025
3 checks passed
@kamilmysliwiec
Copy link
Member

LGTM

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

Successfully merging this pull request may close these issues.

3 participants