Fix SPA serving conflicting with API routes

This commit is contained in:
2026-03-07 03:23:45 +00:00
parent fdafb15b23
commit 78556bbfee

12
main.py
View File

@@ -55,16 +55,8 @@ async def health():
return HealthCheck(status="ok", tools=_tool_status)
# Serve built frontend static files (must be after all /api routes)
# Serve built frontend static files — mounted last so /api routes take priority.
STATIC_DIR = Path(__file__).parent / "static"
if STATIC_DIR.exists():
app.mount("/assets", StaticFiles(directory=STATIC_DIR / "assets"), name="assets")
@app.get("/{full_path:path}")
async def serve_spa(full_path: str):
"""Catch-all: serve index.html for SPA routing."""
file_path = STATIC_DIR / full_path
if file_path.is_file():
return FileResponse(file_path)
return FileResponse(STATIC_DIR / "index.html")
app.mount("/", StaticFiles(directory=STATIC_DIR, html=True), name="static")