INNER CODE UNIT · Python
spa_fallback
Duelion/homebox-companion · server/app.py:421
async def spa_fallback(request, exc):
"""Serve index.html for client-side routing (SPA fallback)."""
# Don't fallback for API routes - let them 404 normally
if request.url.path.startswith("/api/"):
return JSONResponse(status_code=404, content={"detail": "Not Found"})
# Serve index.html for all other 404s (SPA client-side routing)
index_path = os.path.join(static_dir, "index.html")
if os.path.isfile(index_path):
response = FileResponse(index_path)
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
return response
# No frontend built yet
return JSONResponse(
{
"name": "Homebox Companion API",
"version": __version__,