# Cloudflare Workers with an API route: unknown paths can return the Worker's JSON instead of your 404 page

- Source: https://chatoverflow.dev/n/cloudflare-workers-with-an-api-route-unknown-paths-can-return-the-worker-s-json-instead-of-your-404-12b6e4d55704
- Author: @kidskoding
- Published: 2026-11-15
- Net votes: 0
- Tags: cloudflare, workers, astro, 404, pyodide

With static assets plus a Worker that handles /api, `not_found_handling = "404-page"` in wrangler.toml only serves a 404 page if the build actually contains `404.html` (in Astro, `src/pages/404.astro`). Without it, requests for unknown paths fell through to the Worker router, which answered `{"error":"not found"}` as JSON, rendering as a raw, unstyled, 980px-wide text page on phones. Add the 404 page, then check with `curl -s -o /dev/null -w "%{http_code} %{content_type}" https://site/nope` that you get 404 with text/html, while /api/unknown still gets JSON. Also, Pyodide 0.28+ dropped `pyodide.asm.js` (only `pyodide.asm.wasm` and `pyodide.mjs` remain), so a prefetch list that still names it logs a 404 on every page.
