Fix: handle missing frontend gracefully
This commit is contained in:
parent
48bfb0f618
commit
7854bdf14a
12
app/main.py
12
app/main.py
|
|
@ -50,8 +50,10 @@ async def health():
|
||||||
|
|
||||||
# Serve static frontend (will be mounted if exists)
|
# Serve static frontend (will be mounted if exists)
|
||||||
FRONTEND_DIR = "/app/frontend"
|
FRONTEND_DIR = "/app/frontend"
|
||||||
if os.path.exists(FRONTEND_DIR):
|
ASSETS_DIR = f"{FRONTEND_DIR}/assets"
|
||||||
app.mount("/assets", StaticFiles(directory=f"{FRONTEND_DIR}/assets"), name="assets")
|
|
||||||
|
if os.path.exists(FRONTEND_DIR) and os.path.exists(ASSETS_DIR):
|
||||||
|
app.mount("/assets", StaticFiles(directory=ASSETS_DIR), name="assets")
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def serve_frontend():
|
async def serve_frontend():
|
||||||
|
|
@ -59,12 +61,14 @@ if os.path.exists(FRONTEND_DIR):
|
||||||
|
|
||||||
@app.get("/{path:path}")
|
@app.get("/{path:path}")
|
||||||
async def serve_spa(path: str):
|
async def serve_spa(path: str):
|
||||||
|
if path.startswith("api/"):
|
||||||
|
return None # Let API routes handle
|
||||||
file_path = f"{FRONTEND_DIR}/{path}"
|
file_path = f"{FRONTEND_DIR}/{path}"
|
||||||
if os.path.exists(file_path) and os.path.isfile(file_path):
|
if os.path.exists(file_path) and os.path.isfile(file_path):
|
||||||
return FileResponse(file_path)
|
return FileResponse(file_path)
|
||||||
return FileResponse(f"{FRONTEND_DIR}/index.html")
|
return FileResponse(f"{FRONTEND_DIR}/index.html")
|
||||||
else:
|
|
||||||
# Fallback: serve basic info page
|
# Fallback: serve basic info page when no frontend
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root():
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue