from __future__ import annotations import os from pathlib import Path from fastapi import FastAPI from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse from fastapi.staticfiles import StaticFiles SITE_ROOT = Path(os.environ.get("SITE_ROOT", "/data")).resolve() REPORT = SITE_ROOT / "analysis" / "report.html" app = FastAPI(title="Birch HTML Benchmark") @app.get("/") def root(): if REPORT.exists(): return RedirectResponse("/analysis/report.html", status_code=302) return HTMLResponse( "Birch HTML Benchmark" "

Birch HTML Benchmark

" f"

Report not found at {REPORT}. " "Check that the bucket is mounted at /data.

", status_code=503, ) @app.get("/healthz") def healthz(): return { "ok": REPORT.exists(), "site_root": str(SITE_ROOT), "report": str(REPORT), } @app.get("/analysis/report.html") def report(): if REPORT.exists(): return FileResponse(REPORT) return root() if SITE_ROOT.exists(): app.mount("/", StaticFiles(directory=SITE_ROOT, html=True), name="site")