Skip to content

fix: add SPA fallback for client-side routing#13

Merged
lewisjared merged 1 commit intomainfrom
redirect
Mar 6, 2026
Merged

fix: add SPA fallback for client-side routing#13
lewisjared merged 1 commit intomainfrom
redirect

Conversation

@lewisjared
Copy link
Contributor

@lewisjared lewisjared commented Mar 6, 2026

Summary

  • Adds SPAStaticFiles class that extends Starlette's StaticFiles to support SPA fallback routing
  • When a requested path doesn't match a real static file, serves index.html instead of returning 404
  • Enables client-side routing (e.g. /diagnostics?view=cards) to work correctly when served from the FastAPI backend

This matches the behavior of Netlify's /* /index.html 200 redirect rule. API routes under /api/v1/ are unaffected since they are registered before the static mount.

Test plan

  • Navigate to /diagnostics?view=cards and verify the frontend app loads
  • Verify static assets (JS, CSS, images) still load correctly
  • Verify API routes (/api/v1/*) still respond normally
  • Verify the root path / still serves index.html

Replace StaticFiles with SPAStaticFiles that falls back to index.html
when a requested path doesn't match a real static file. This enables
client-side routing (e.g. /diagnostics?view=cards) to work correctly
when served from the FastAPI backend, matching the behavior of Netlify's
redirect-to-index.html pattern.
@netlify
Copy link

netlify bot commented Mar 6, 2026

Deploy Preview for climate-ref canceled.

Name Link
🔨 Latest commit 8491802
🔍 Latest deploy log https://app.netlify.com/projects/climate-ref/deploys/69aa251aaa6e1800084d3aee

@lewisjared lewisjared merged commit ca52d26 into main Mar 6, 2026
7 checks passed
@lewisjared lewisjared deleted the redirect branch March 6, 2026 00:55
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