Repository navigation
feat: inline site.notFound on the Cloudflare Worker (refs #309) - #384
Merged
Merged
Conversation
build --target cloudflare no longer refuses site.notFound. The one configured page is small, singular and static, so the build reads it (64 KiB cap, must decode as UTF-8) and carries it inline in the artifact as a `respond` route at /404.html, answering the same status, headers and method rules as the self-hosted, Vercel and AWS targets: 404 with the page for an unmatched GET/HEAD, security headers, the plain-text `Not found` preserved for other methods, and /404.html itself still reachable directly. Every other page/static/ download route stays refused, since those are open-ended rather than one bounded page. Verified against real workerd via `wrangler dev --local` in a scratch directory: status 404, content-type, cache-control: no-store, x-content-type-options: nosniff and the rest of the security headers on GET, correct content-length with an empty body on HEAD, and POST still answering the plain-text Not found. - src/site.ts: inlineNotFound() reads and validates the page, rewrites the generated /404.html route to a respond route - src/build-cloudflare.ts: calls inlineNotFound() after applySite(); artifact.notFound: true records that the fallback is available - src/cloudflare.ts: an unmatched GET/HEAD with artifact.notFound set is answered from the inlined /404.html route with status 404 - test/site.test.ts: replaces the old "refused" assertion with coverage of the inline path (GET/HEAD/POST, direct /404.html access, shadowing) and its bounds (64 KiB cap, invalid UTF-8, other page routes still refused) - docs/CLOUDFLARE.md, docs/SITE.md, docs/OPEN-DECISIONS.md: document the decision and the workerd verification Options considered (docs/OPEN-DECISIONS.md has the full writeup): 1. Inline the page as a string (chosen) — bounded, no new dependency, small change confined to src/build-cloudflare.ts + src/site.ts. 2. Workers Static Assets binding (`assets` in wrangler config) — would need new build output shape and validation for a whole class of files; oversized for one bounded page. 3. Keep refusing and document the respond/function-route alternative — left the issue's Cloudflare acceptance item unmet. npm run check:docs, npm ci and npm run verify all pass. Core package entry count is 430 of the 440-entry budget in scripts/package-audit.ts (not raised). Co-Authored-By: Claude Sonnet 5 <[email protected]>
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
Closes the remaining gap from #309:
build --target cloudflarerefusedsite.notFoundoutright because that target has no static-asset binding. That page is small, singular and static, so the build now reads it and carries it inline in the Worker artifact as arespondroute at/404.html, answering the same status, headers and method rules as self-hosted, Vercel and AWS.Every other
page/static/downloadroute stays refused — those are open-ended, not one bounded page, and would need a real Workers Static Assets binding.What changed
src/site.ts—inlineNotFound()reads the configured page, enforces a 64 KiB size cap and valid UTF-8, and rewrites the generated/404.htmlroute into an ordinaryrespondroute (no template, no request data, no per-request file read).src/build-cloudflare.ts— callsinlineNotFound()afterapplySite(); the artifact recordsnotFound: truewhen the fallback is present.src/cloudflare.ts— an unmatchedGET/HEADis now answered from the inlined/404.htmlroute with status 404 whenartifact.notFoundis set; every other method still gets the plain-textNot found.test/site.test.ts— replaces the old "Cloudflare refusessite.notFound" assertion with coverage of the inline path (GET/HEAD/POST, direct/404.htmlaccess, shadowing by a declared route) and its bounds (64 KiB cap, invalid UTF-8 refused, other page routes still refused).docs/CLOUDFLARE.md,docs/SITE.md,docs/OPEN-DECISIONS.md— document the decision, the size/encoding bounds, and the workerd verification.llms-full.txtregenerated (npm run docs:llms).Options considered (recorded in
docs/OPEN-DECISIONS.md)src/build-cloudflare.ts+src/site.ts.assetsin wrangler config)respond/function-route alternativeVerified on real workerd
Built
examples/not-foundfor thecloudflaretarget and ran the artifact underwrangler dev --localin a scratch directory (no login/deploy/credentials), following the pattern inscripts/workerd-parity.ts(#381):GET /nope?q=1→404,content-type: text/html; charset=utf-8,cache-control: no-store,x-content-type-options: nosniff, and the rest of the configured security headers; body is the configured page.HEAD /nope→404, empty body, correctcontent-length.POST /nope→404, plain-textNot found(unchanged from before this change).GET /404.htmldirectly →200with the page.GET /→ unaffected (200).Checks run
npm cinpm run check:docs(trust-model prose, version statements, local links, guidance claims, yaml-reference, llms-full, cookbook index, plugin distribution)npm run verify(lint, typecheck, check, build,npm test— 676 passing,verify:workspaces)scripts/package-audit.ts(not raised)Open decisions
None new.
docs/OPEN-DECISIONS.mdrecords this as an accepted decision (inline over an assets binding) and notes that the assets-binding design should only be revisited if a future site convention or route type needs to serve more than one small file on Cloudflare.Refs #309. Does not close it (leaving that to the reporter/maintainer to confirm). Siblings #383 and #330 are untouched — no changes to llms.txt/context/recipes/packages/ui.
🤖 Generated with Claude Code