fix(static-assets): accept Request | string | URL in fetch()#7
Open
jonasnobile wants to merge 1 commit into
Open
fix(static-assets): accept Request | string | URL in fetch()#7jonasnobile wants to merge 1 commit into
jonasnobile wants to merge 1 commit into
Conversation
Production Cloudflare's ASSETS binding accepts a Request, a URL string, or a URL object. `@astrojs/cloudflare`'s generated worker calls `env.ASSETS.fetch(request.url.replace(...))` (a string), so any Astro SSR project on lopata 500s with `TypeError: "undefined" cannot be parsed as a URL` on the first non-static route. Widen `StaticAssets.fetch` to accept all three forms, derive `url` and an optional `request` from the input. `serveFile()` already accepted `request?`, so conditional-request handling (If-None-Match → 304) is naturally skipped when only a URL is passed — same as production behavior in that case. Adds three test cases covering the new input forms. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
89377c5 to
e6e2dd8
Compare
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.
Summary
Lopata's
StaticAssets.fetch()previously accepted onlyRequest, immediately doingnew URL(request.url). Production Cloudflare'sASSETSbinding acceptsRequest | string | URL, and@astrojs/cloudflare's generated worker passes a string:As a result, any Astro SSR project running on lopata 500s on the first non-static route with:
(Caught while building
nctype.comon Astro 5 +@astrojs/cloudflare@12.6.0. The same shape likely affects other Workers SSR adapters that follow the same pattern.)Fix
Widen
fetch()to acceptRequest | string | URL. Deriveurlfrom any of the three; keeprequestas an optionalRequestsoserveFile()'s existing conditional-request handling (If-None-Match→304) still works when a realRequestis passed. When only a string/URL is given,requestisundefinedandserveFile()skips conditional handling — matches production behavior for that call shape.Test plan
bun test tests/static-assets.test.ts→ 63 pass, 0 fail (60 existing + 3 new)bunx biome lint src/bindings/static-assets.ts tests/static-assets.test.ts→ cleanbunx dprint check ...→ clean@astrojs/cloudflareSSR route on lopata returns 200 instead of 500 after patchThe three new tests cover the contract directly:
fetch accepts a URL stringfetch accepts a URL objectfetch with string input skips conditional-request handling (no If-None-Match)🤖 Generated with Claude Code