Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@amondnet
Copy link
Contributor

Fixes middleware not inheriting base URL when sub-app is mounted. Middleware matchers now correctly see adjusted pathname (without base prefix), while route handlers continue to see the full pathname.

This fix adjusts event.url.pathname before calling child middleware, then restores it before calling the route handler (via wrapped next callback). The try/finally block ensures pathname is always restored.

Changes:

  • Modified H3Core.mount() to adjust pathname for child middleware
  • Added wrappedNext callback to restore pathname before route handler
  • Added comprehensive tests for middleware mounting scenarios
  • Updated existing test to use relative paths in mounted middleware

Test Results:

  • All 712 functional tests pass
  • Bundle size increased by ~150 bytes (acceptable tradeoff)

resolves #1208

Fixes middleware not inheriting base URL when sub-app is mounted.
Middleware matchers now correctly see adjusted pathname (without base prefix),
while route handlers continue to see the full pathname.

This fix adjusts `event.url.pathname` before calling child middleware,
then restores it before calling the route handler (via wrapped next callback).
The try/finally block ensures pathname is always restored.

Changes:
- Modified H3Core.mount() to adjust pathname for child middleware
- Added wrappedNext callback to restore pathname before route handler
- Added comprehensive tests for middleware mounting scenarios
- Updated existing test to use relative paths in mounted middleware

Test Results:
- All 712 functional tests pass
- Bundle size increased by ~150 bytes (acceptable tradeoff)

Fixes h3js#1208
@amondnet amondnet requested a review from pi0 as a code owner October 27, 2025 05:41
@pi0 pi0 changed the title fix(mount): adjust pathname for mounted middleware fix: adjust pathname for mounted sub-app routed middleware Oct 27, 2025
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ❤️

@pi0 pi0 merged commit a05c860 into h3js:main Oct 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mounted middleware from subapp don't inherit base url

2 participants