fix: prevent SPA fallback from capturing API routes
This commit is contained in:
parent
8f130b2cbd
commit
15867ecf92
10
app/main.py
10
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue