Add frontend fallback resolver

This commit is contained in:
Jack Kingsman
2026-02-24 00:18:11 -08:00
parent 17e526697f
commit c25b21469e
3 changed files with 24 additions and 5 deletions
+13
View File
@@ -120,3 +120,16 @@ def register_frontend_static_routes(app: FastAPI, frontend_dir: Path) -> bool:
logger.info("Serving frontend from %s", frontend_dir)
return True
def register_frontend_missing_fallback(app: FastAPI) -> None:
"""Register a fallback route that tells the user to build the frontend."""
@app.get("/", include_in_schema=False)
async def frontend_not_built():
return JSONResponse(
status_code=404,
content={
"detail": "Frontend not built. Run: cd frontend && npm install && npm run build"
},
)
+3 -2
View File
@@ -8,7 +8,7 @@ from fastapi.responses import JSONResponse
from app.config import setup_logging
from app.database import db
from app.frontend_static import register_frontend_static_routes
from app.frontend_static import register_frontend_missing_fallback, register_frontend_static_routes
from app.radio import RadioDisconnectedError, radio_manager
from app.radio_sync import (
stop_message_polling,
@@ -109,4 +109,5 @@ app.include_router(ws.router, prefix="/api")
# Serve frontend static files in production
FRONTEND_DIR = Path(__file__).parent.parent / "frontend" / "dist"
register_frontend_static_routes(app, FRONTEND_DIR)
if not register_frontend_static_routes(app, FRONTEND_DIR):
register_frontend_missing_fallback(app)