diff --git a/backend/main.py b/backend/main.py index d9e0e0b..3ac3bd5 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1494,4 +1494,18 @@ def startup(): seed_defaults(data["oils_meta"], data["recipes"]) if os.path.isdir(FRONTEND_DIR): - app.mount("/", StaticFiles(directory=FRONTEND_DIR, html=True), name="frontend") + # Serve static assets (js/css/images) directly + app.mount("/assets", StaticFiles(directory=os.path.join(FRONTEND_DIR, "assets")), name="assets") + app.mount("/public", StaticFiles(directory=FRONTEND_DIR), name="public") + + # SPA fallback: any non-API, non-asset route returns index.html + from fastapi.responses import FileResponse + + @app.get("/{path:path}") + async def spa_fallback(path: str): + # Serve actual files if they exist (favicon, icons, etc.) + file_path = os.path.join(FRONTEND_DIR, path) + if os.path.isfile(file_path): + return FileResponse(file_path) + # Otherwise return index.html for Vue Router + return FileResponse(os.path.join(FRONTEND_DIR, "index.html"))