fix: use catch-all GET not mount for SPA, preserve WS routes
This commit is contained in:
parent
67d738baf3
commit
54c1e9d92c
1 changed files with 18 additions and 4 deletions
|
|
@ -990,6 +990,10 @@ 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")
|
||||||
|
|
||||||
|
# Mount /assets for Vite-built JS/CSS bundles
|
||||||
|
if STATIC_DIR.exists() and (STATIC_DIR / "assets").exists():
|
||||||
|
app.mount("/assets", StaticFiles(directory=str(STATIC_DIR / "assets")), name="assets")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def serve_index():
|
async def serve_index():
|
||||||
|
|
@ -999,7 +1003,17 @@ async def serve_index():
|
||||||
return {"message": "Claude Persistent Agent API v3.0", "docs": "/docs"}
|
return {"message": "Claude Persistent Agent API v3.0", "docs": "/docs"}
|
||||||
|
|
||||||
|
|
||||||
# Mount static assets AFTER all API/WS routes are registered
|
@app.get("/{full_path:path}")
|
||||||
# This ensures /api/* and WebSocket routes take priority
|
async def serve_spa(full_path: str):
|
||||||
if STATIC_DIR.exists():
|
"""Serve React SPA for all non-API routes. API and WS are handled above."""
|
||||||
app.mount("/", StaticFiles(directory=str(STATIC_DIR), html=True), name="spa")
|
if full_path.startswith("api"):
|
||||||
|
raise HTTPException(404)
|
||||||
|
# Try serving the file directly (e.g. vite.svg, favicon)
|
||||||
|
file_path = STATIC_DIR / full_path
|
||||||
|
if file_path.is_file():
|
||||||
|
return FileResponse(str(file_path))
|
||||||
|
# Fall back to index.html for SPA routing
|
||||||
|
index = STATIC_DIR / "index.html"
|
||||||
|
if index.exists():
|
||||||
|
return FileResponse(str(index))
|
||||||
|
raise HTTPException(404)
|
||||||
|
|
|
||||||
Reference in a new issue