Skip to content

fix: robust 404 handling for all unmatched paths - #90

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/robust-404-handling
Apr 8, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/robust-404-handling

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Apr 8, 2026 •

Copy link
Copy Markdown
Member

The notFound handler now returns 404 for all unmatched paths instead of
rendering the index page as a 200 SPA fallback. Three layers of defense:

  1. Dot-prefixed segments (/.well-known/, /.git/, /.env) → 404 early exit
  2. File extension in last segment (wp-login.php, robots.txt) → 404
  3. All remaining paths: try rendering index with 404 status; if the
    render throws (e.g. index expects loader props), catch and serve
    the error page as 404

Previously, paths like /wp-admin, /foo/bar/baz, and
/.well-known/traffic-advice either returned 500 (index crash) or 200
(SPA fallback). Now they all return 404.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com


Note

Medium Risk
Changes the pages-mode app.notFound behavior from a 200 SPA fallback to always returning 404 for unknown routes, which can affect SEO/caching and any clients relying on the previous 200 response. Logic is localized to routing plus expanded tests, reducing regression risk elsewhere.

Overview
Makes pages-mode unmatched routes return real 404s instead of a 200 SPA index fallback.

The app.notFound handler now (1) blocks any /. path segment (e.g. /.well-known, /.git, /.env), (2) blocks last-segment dotted paths (e.g. robots.txt, wp-login.php), and (3) for remaining unknown paths attempts to render index but wraps it in a try/catch and forces status 404 (falling back to 404.html/default error page if rendering throws).

Adds integration + unit coverage for common bot-probe/unknown paths, API-prefix behavior, and non-GET methods to ensure consistent 404 responses.

Reviewed by Cursor Bugbot for commit b745ff3. Bugbot is set up for automated code reviews on this repo. Configure here.

The notFound handler now returns 404 for all unmatched paths instead of
rendering the index page as a 200 SPA fallback. Three layers of defense:

1. Dot-prefixed segments (/.well-known/, /.git/, /.env) → 404 early exit
2. File extension in last segment (wp-login.php, robots.txt) → 404
3. All remaining paths: try rendering index with 404 status; if the
   render throws (e.g. index expects loader props), catch and serve
   the error page as 404

Previously, paths like /wp-admin, /foo/bar/baz, and
/.well-known/traffic-advice either returned 500 (index crash) or 200
(SPA fallback). Now they all return 404.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Brooooooklyn
Brooooooklyn merged commit 3b55e43 into main Apr 8, 2026
9 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/robust-404-handling branch April 8, 2026 07:56
cpojer pushed a commit that referenced this pull request Sep 11, 2026
Asset-heavy deploys (e.g. 87 MiB / 199 files) saw "Connection Lost"
because `parseMultipart` + sequential KV/R2 puts ran in the handler
body before `new Response(stream)`, blocking 30-60s with zero
response bytes. CF edge / intermediaries closed the socket before
the NDJSON stream ever started.

Restructure the handler: build the TransformStream + writer +
heartbeat first, wrap parse + validate + full pipeline in a
fire-and-forget IIFE that writes to the stream, and return the
Response in milliseconds so headers flush immediately. In-parse
error branches that used to return 4xx JSON now emit NDJSON
`{event:'error'}` through the shared writer; pre-stream guards
(401/403/404/409/invalid content-type) still return 4xx. Dedupe
short-circuit now emits through the same writer instead of building
its own Response.

Plumb `DEPLOY_HEARTBEAT_INTERVAL_MS` (default 15000) so tests can
exercise the heartbeat path without waiting real seconds. Migrate
25 test assertions from `toBe(400|413|429)` to NDJSON error-event
checks, and add two regression tests: incremental stream consumption
proves `start` is the first non-heartbeat event, and a sub-second
heartbeat interval proves heartbeats fire across the full pipeline.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant