From e90dbc101215cd4d02334391f6637cf633631831 Mon Sep 17 00:00:00 2001 From: Ahmed Dlshad Date: Tue, 23 Jun 2026 20:47:22 +0300 Subject: [PATCH] fix(routes): 500 (not 404) when the app-shell index.html is missing (#4791) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to #4637. serve_index — the handler for / and the SPA deep-link routes (/notes, /calendar, /cookbook, /email, /memory, /gallery, /tasks, /library) — pre-checked os.path.exists and raised its own HTTPException(404, "index.html not found") when the bundle was missing. So a missing core template returned 404 before serve_html_with_nonce's 500 could fire, the one inconsistency left after #4637. index.html is a fixed, app-bundled template; a missing one is a broken deployment (server fault), not a client "not found", so it should surface as a logged 500 in 5xx alerting rather than a 404. Keep the static->root fallback, drop the redundant existence guard and the dead-end 404, and let the shared helper handle the missing case. Verified against the running app: / and /notes return 200 with the bundle present and a logged 500 when index.html is absent. Co-authored-by: Claude Opus 4.8 --- app.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index b96e7a01b..b6987acab 100644 --- a/app.py +++ b/app.py @@ -806,10 +806,12 @@ async def serve_index(request: Request): static_path = abs_join(BASE_DIR, "static/index.html") if os.path.exists(static_path): return serve_html_with_nonce(request, static_path) - root_path = abs_join(BASE_DIR, "index.html") - if os.path.exists(root_path): - return serve_html_with_nonce(request, root_path) - raise HTTPException(404, "index.html not found") + # No static bundle — fall back to a root-level index.html if one is shipped. + # If neither exists, serve_html_with_nonce logs it and returns a generic 500: + # a missing index.html is a broken deployment (server fault), not a client + # "not found". This keeps the app-shell route consistent with the other + # bundled-template routes instead of mislabelling the fault as a 404. + return serve_html_with_nonce(request, abs_join(BASE_DIR, "index.html")) @app.get("/notes") async def serve_notes(request: Request):