Fix: handle missing frontend gracefully
This commit is contained in:
parent
48bfb0f618
commit
7854bdf14a
16
app/main.py
16
app/main.py
|
|
@ -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,14 +61,16 @@ 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():
|
||||
|
||||
# Fallback: serve basic info page when no frontend
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {
|
||||
"service": settings.APP_NAME,
|
||||
"version": settings.APP_VERSION,
|
||||
|
|
|
|||
Loading…
Reference in New Issue