From 84c500d018f7637c172a0ddce7747a021094e40e Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Sun, 22 Mar 2026 23:32:52 -0700 Subject: [PATCH] Add clearer warning on frontend fetching invalid backend --- app/frontend_static.py | 12 ++++++++++++ tests/test_frontend_static.py | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/frontend_static.py b/app/frontend_static.py index 7505faa..49e8551 100644 --- a/app/frontend_static.py +++ b/app/frontend_static.py @@ -139,6 +139,18 @@ def register_frontend_static_routes(app: FastAPI, frontend_dir: Path) -> bool: @app.get("/{path:path}") async def serve_frontend(path: str): """Serve frontend files, falling back to index.html for SPA routing.""" + if path == "api" or path.startswith("api/"): + return JSONResponse( + status_code=404, + content={ + "detail": ( + "API endpoint not found. If you are seeing this in response to a " + "frontend request, you may be running a newer frontend with an older " + "backend or vice versa. A full update is suggested." + ) + }, + ) + file_path = (frontend_dir / path).resolve() try: file_path.relative_to(frontend_dir) diff --git a/tests/test_frontend_static.py b/tests/test_frontend_static.py index f1cadf6..5372df6 100644 --- a/tests/test_frontend_static.py +++ b/tests/test_frontend_static.py @@ -86,6 +86,16 @@ def test_valid_dist_serves_static_and_spa_fallback(tmp_path): assert "index page" in missing_response.text assert missing_response.headers["cache-control"] == INDEX_CACHE_CONTROL + missing_api_response = client.get("/api/not-a-real-endpoint") + assert missing_api_response.status_code == 404 + assert missing_api_response.json() == { + "detail": ( + "API endpoint not found. If you are seeing this in response to a frontend " + "request, you may be running a newer frontend with an older backend or vice " + "versa. A full update is suggested." + ) + } + asset_response = client.get("/assets/app.js") assert asset_response.status_code == 200 assert "console.log('ok');" in asset_response.text