fix: resolve wildcard paths in encapsulated contexts#574
Merged
mcollina merged 1 commit intofastify:mainfrom Apr 18, 2026
Merged
fix: resolve wildcard paths in encapsulated contexts#574mcollina merged 1 commit intofastify:mainfrom
mcollina merged 1 commit intofastify:mainfrom
Conversation
lpatiny
added a commit
to cheminfo/surge
that referenced
this pull request
Apr 20, 2026
@fastify/static 9.1.1 rewrote the wildcard route handler to use getPathnameForSend(req.raw.url, prefix) where prefix is only the local plugin prefix. When @fastify/swagger-ui registers it inside its /documentation-prefixed encapsulated scope, the handler fails to strip the parent prefix and returns 404 for every /documentation/static/*.css and .js asset, so the Swagger UI page renders blank. - Pin @fastify/static to 9.1.0 in dependencies and overrides so swagger-ui's transitive copy is also pinned. - Commit package-lock.json (drop the .npmrc package-lock=false flag) so the pinned version is reproducible in CI and the Docker image build. - Extract server construction into src/server.js (buildServer) so the app can be exercised via fastify.inject() in tests. - Add a regression test covering GET /documentation/ and GET /documentation/static/index.css. Upstream fix fastify/fastify-static#574 is merged but not yet released; once @fastify/static 9.1.2+ ships with the fix, this pin can be removed. refs: fastify/fastify-static#573 refs: fastify/fastify-swagger-ui#268
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
@fastify/staticv9.1.1 switched wildcard path resolution to derive the pathname fromreq.raw.urland the local plugin prefix.That breaks encapsulated registrations because
req.raw.urlincludes the outer plugin prefix while the local static prefix does not. As a result, nested wildcard mounts fall through toreply.callNotFound()and valid static assets start returning 404.This reproduces the regression reported in fastify/fastify-swagger-ui#268.
Solution
req.routeOptions.url, which includes the full routed prefixTesting
npm testnpm run lint