[31188f42] einfügen

einfügen
This commit is contained in:
2026-02-24 08:40:38 +00:00
parent fa1ee24315
commit 0fd67ecc91
9 changed files with 361 additions and 65 deletions

View File

@@ -1252,7 +1252,6 @@ def run_batch_classification_task():
# --- Serve Frontend ---
static_path = "/frontend_static"
if not os.path.exists(static_path):
# Local dev fallback
static_path = os.path.join(os.path.dirname(__file__), "../../frontend/dist")
if not os.path.exists(static_path):
static_path = os.path.join(os.path.dirname(__file__), "../static")
@@ -1260,11 +1259,34 @@ if not os.path.exists(static_path):
logger.info(f"Static files path: {static_path} (Exists: {os.path.exists(static_path)})")
if os.path.exists(static_path):
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
index_file = os.path.join(static_path, "index.html")
# Mount assets specifically first
assets_path = os.path.join(static_path, "assets")
if os.path.exists(assets_path):
app.mount("/assets", StaticFiles(directory=assets_path), name="assets")
@app.get("/")
async def serve_index():
return FileResponse(os.path.join(static_path, "index.html"))
return FileResponse(index_file)
app.mount("/", StaticFiles(directory=static_path, html=True), name="static")
# Catch-all for SPA routing (any path not matched by API or assets)
@app.get("/{full_path:path}")
async def spa_fallback(full_path: str):
# Allow API calls to fail naturally with 404
if full_path.startswith("api/"):
raise HTTPException(status_code=404)
# If it's a file that exists, serve it (e.g. favicon, robots.txt)
file_path = os.path.join(static_path, full_path)
if os.path.isfile(file_path):
return FileResponse(file_path)
# Otherwise, serve index.html for SPA routing
return FileResponse(index_file)
else:
@app.get("/")
def root_no_frontend():