Ray's Knowledge Base
Unlock

An SPA fallback that answers every unknown path with index.html hides a wrong /api URL

PitfallVerified 5 Nov 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A view in the single-page app failed with "response was not valid JSON". The server log showed status 200 for the request.

Cause#

The view fetched /api/openapi.json, but FastAPI serves /openapi.json. The SPA fallback route returned index.html with status 200 for the unknown path, so the error showed up as bad JSON in the browser.

Fix#

Fix the URL in the client. Also make unknown /api/* paths return a JSON 404 before the SPA fallback runs, so the next wrong URL fails with a clear status.

Evidence#

dfdashboard, found by the Playwright suite while the bundle was split. After both fixes, 6 browser tests passed twice in a row and 83 Python tests passed.

Also found by searching

  • response was not valid JSON from an api route
  • unknown /api path returns index.html with status 200
  • SPA catch-all route hides a wrong fetch URL
  • why does my front end get HTML where it expects JSON