Fix trailing slash handling for dynamic file endpoints in dev mode#17224
Open
astrobot-houston wants to merge 1 commit into
Open
Fix trailing slash handling for dynamic file endpoints in dev mode#17224astrobot-houston wants to merge 1 commit into
astrobot-houston wants to merge 1 commit into
Conversation
…17001)\n\ntrailingSlashForPath used pathname (null for dynamic routes) to check\nfor file extensions, causing dynamic file endpoints like [name].json.ts\nto inherit trailingSlash: 'always' instead of forcing 'never'. Use the\nroute string from joinSegments as a fallback, which preserves file\nextensions even for dynamic segments.
1 task
🦋 Changeset detectedLatest commit: a501ad8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 393 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Changes
src/pages/api/[name].json.tswithtrailingSlash: "always"now correctly return 200 for/api/bar.jsonand 404 for/api/bar.json/in dev mode, matching production behavior and the documented Astro v6 rule that file endpoints are never served with a trailing slash.trailingSlashForPathcheckedpathname && hasFileExtension(pathname), butpathnameisnullfor dynamic routes (any segment with a param). The fix adds an optionalroutefallback parameter — the string fromjoinSegments— which preserves file extensions even for dynamic segments (e.g.,/api/[name].json), allowing the file-extension check to work correctly.Testing
'dynamic file endpoints force trailingSlash never. issues#17001'inpackages/astro/test/units/routing/manifest.test.ts: creates a[name].json.tspage undertrailingSlash: "always"and asserts the generated route pattern matches without a trailing slash and rejects with one.Docs
Closes #17001