Skip to content

[Request]: Let a project configure the 404 response for unmatched routes #309

Closed

Description

@jimhoyd

Problem: A request that matches no route always gets the built-in plain-text response, and nothing in the schema or docs lets a project change it.

Reproduced on current source: a project with one route /, then curl -i localhost:PORT/nope returns 404, content-type: text/plain; charset=utf-8, body Not found.

Any site with pages needs a branded or on-topic 404. Today the workaround is a catch-all route /{path} with a function or page, which costs a route, a sandbox decision and loses the accurate unmatched-route behavior. The blog agent listed this under "Not found / gaps" and wrote an HTML 404 inside a function.

(I found no existing issue: searched open and closed for 404 / not found / error page.)

Proposed behavior: A top-level key (for example site.notFound: {page: file:...} or notFound: {status: 404, page: ...}) that serves a static page with status 404 for unmatched routes.

Acceptance:

  • The page is served with status 404 and content-type: text/html, and works with urlcode build --target static (as 404.html) and --target cloudflare.
  • urlcode schema documents the key.
  • A recipe or fixture in tests/requests.json asserts the status and body.
  • If the answer is "use a catch-all route", document that pattern instead and close this.

Evidence: benchmarks/results/blog-ab-2026-09-20/agent-b-urlcode/REPORT.md ("Not found / gaps").

Activity

  1. added
    enhancement
    ai-first
    in-progress
    on Sep 20, 2026
  2. jimhoyd commented on Sep 20, 2026

    @jimhoyd
    CollaboratorAuthor

    Progress: an agent has started on this; a PR will be linked here when it opens.

  3. removed
    in-progress
    on Sep 20, 2026
  4. jimhoyd commented on Sep 20, 2026

    @jimhoyd
    CollaboratorAuthor

    Shipped in #316: site.notFound: serves that page with status 404 for unmatched GET/HEAD on self-hosted, Vercel and AWS, and build --target static writes 404.html. build --target cloudflare refuses it explicitly (no asset binding), so the issue's Cloudflare acceptance item is not met; keeping this open until an asset-binding decision is made. Other methods keep the plain-text Not found.

  5. added
    in-progress
    on Sep 21, 2026
  6. jimhoyd commented on Sep 21, 2026

    @jimhoyd
    CollaboratorAuthor

    Progress: an agent has started on this; a PR (or a recommendation comment) will be linked here.

  7. removed
    in-progress
    on Sep 21, 2026
  8. jimhoyd commented on Sep 21, 2026

    @jimhoyd
    CollaboratorAuthor

    Fixed in #384: site.notFound is now inlined into the Worker bundle for the Cloudflare target (bounded to 64 KiB, valid UTF-8), so GET/HEAD on an unmatched route answers with the configured page and status 404, HEAD is empty with the right content-length, POST keeps the plain-text Not found, and a direct GET /404.html still returns 200. Verified on real workerd (wrangler dev --local, nothing deployed). A Workers Static Assets binding for serving more than one small file is deferred and recorded in docs/OPEN-DECISIONS.md. Core package entry count: 430 of 440, unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-firstenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions