fix: mount SPA at root, fix WS route priority
This commit is contained in:
parent
3cd63de3f0
commit
67d738baf3
1 changed files with 4 additions and 12 deletions
|
|
@ -989,9 +989,6 @@ async def remove_mcp_server(name: str):
|
||||||
STATIC_DIR = Path("/app/static")
|
STATIC_DIR = Path("/app/static")
|
||||||
if not STATIC_DIR.exists():
|
if not STATIC_DIR.exists():
|
||||||
STATIC_DIR = Path("/app/frontend/dist")
|
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("/")
|
@app.get("/")
|
||||||
|
|
@ -1002,12 +999,7 @@ async def serve_index():
|
||||||
return {"message": "Claude Persistent Agent API v3.0", "docs": "/docs"}
|
return {"message": "Claude Persistent Agent API v3.0", "docs": "/docs"}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/{full_path:path}")
|
# Mount static assets AFTER all API/WS routes are registered
|
||||||
async def serve_spa(full_path: str):
|
# This ensures /api/* and WebSocket routes take priority
|
||||||
"""Serve React SPA for all non-API routes."""
|
if STATIC_DIR.exists():
|
||||||
if full_path.startswith("api/"):
|
app.mount("/", StaticFiles(directory=str(STATIC_DIR), html=True), name="spa")
|
||||||
raise HTTPException(404)
|
|
||||||
index = STATIC_DIR / "index.html"
|
|
||||||
if index.exists():
|
|
||||||
return FileResponse(str(index))
|
|
||||||
raise HTTPException(404)
|
|
||||||
|
|
|
||||||
Reference in a new issue