From 15867ecf925233a00b511176b8439e0b4a6387ec Mon Sep 17 00:00:00 2001 From: Ricel Leite Date: Thu, 19 Feb 2026 00:51:33 -0300 Subject: [PATCH] fix: prevent SPA fallback from capturing API routes --- app/main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 89dcdd9..fa5d8ee 100644 --- a/app/main.py +++ b/app/main.py @@ -74,10 +74,14 @@ if os.path.exists(FRONTEND_DIR) and os.path.exists(ASSETS_DIR): async def serve_frontend(): return FileResponse(f"{FRONTEND_DIR}/index.html") - @app.get("/{path:path}") + # SPA fallback - MUST be last and NOT capture /api/* + @app.get("/{path:path}", include_in_schema=False) async def serve_spa(path: str): - if path.startswith("api/"): - return None # Let API routes handle + # Explicitly skip API routes + if path.startswith("api"): + from fastapi import HTTPException + raise HTTPException(status_code=404, detail="Not Found") + file_path = f"{FRONTEND_DIR}/{path}" if os.path.exists(file_path) and os.path.isfile(file_path): return FileResponse(file_path)