Fix: handle missing frontend gracefully

This commit is contained in:
Ricel Leite 2026-02-18 20:01:13 -03:00
parent 48bfb0f618
commit 7854bdf14a
1 changed files with 16 additions and 12 deletions

View File

@ -50,8 +50,10 @@ async def health():
# Serve static frontend (will be mounted if exists)
FRONTEND_DIR = "/app/frontend"
if os.path.exists(FRONTEND_DIR):
app.mount("/assets", StaticFiles(directory=f"{FRONTEND_DIR}/assets"), name="assets")
ASSETS_DIR = f"{FRONTEND_DIR}/assets"
if os.path.exists(FRONTEND_DIR) and os.path.exists(ASSETS_DIR):
app.mount("/assets", StaticFiles(directory=ASSETS_DIR), name="assets")
@app.get("/")
async def serve_frontend():
@ -59,17 +61,19 @@ if os.path.exists(FRONTEND_DIR):
@app.get("/{path:path}")
async def serve_spa(path: str):
if path.startswith("api/"):
return None # Let API routes handle
file_path = f"{FRONTEND_DIR}/{path}"
if os.path.exists(file_path) and os.path.isfile(file_path):
return FileResponse(file_path)
return FileResponse(f"{FRONTEND_DIR}/index.html")
else:
# Fallback: serve basic info page
@app.get("/")
async def root():
return {
"service": settings.APP_NAME,
"version": settings.APP_VERSION,
"docs": "/api/docs",
"health": "/api/health"
}
# Fallback: serve basic info page when no frontend
@app.get("/")
async def root():
return {
"service": settings.APP_NAME,
"version": settings.APP_VERSION,
"docs": "/api/docs",
"health": "/api/health"
}