fix: mount SPA at root, fix WS route priority

This commit is contained in:
Zac Gaetano 2026-04-05 11:06:44 -04:00
parent 3cd63de3f0
commit 67d738baf3

View file

@ -989,9 +989,6 @@ async def remove_mcp_server(name: str):
STATIC_DIR = Path("/app/static")
if not STATIC_DIR.exists():
STATIC_DIR = Path("/app/frontend/dist")
if STATIC_DIR.exists():
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
app.mount("/assets", StaticFiles(directory=str(STATIC_DIR / "assets")), name="assets") if (STATIC_DIR / "assets").exists() else None
@app.get("/")
@ -1002,12 +999,7 @@ async def serve_index():
return {"message": "Claude Persistent Agent API v3.0", "docs": "/docs"}
@app.get("/{full_path:path}")
async def serve_spa(full_path: str):
"""Serve React SPA for all non-API routes."""
if full_path.startswith("api/"):
raise HTTPException(404)
index = STATIC_DIR / "index.html"
if index.exists():
return FileResponse(str(index))
raise HTTPException(404)
# Mount static assets AFTER all API/WS routes are registered
# This ensures /api/* and WebSocket routes take priority
if STATIC_DIR.exists():
app.mount("/", StaticFiles(directory=str(STATIC_DIR), html=True), name="spa")