Stream dashboard index.html via FileResponse

This commit is contained in:
Yiorgis Gozadinos 2026-05-26 16:31:41 +03:00
parent 29b3ccdbda
commit 291b565b4c
No known key found for this signature in database

View file

@ -1,18 +1,17 @@
from pathlib import Path
from fastapi import APIRouter
from fastapi.responses import HTMLResponse
from fastapi.responses import FileResponse
router = APIRouter(tags=["dashboard"])
_STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
_INDEX_HTML = (_STATIC_DIR / "index.html").read_text(encoding="utf-8")
_INDEX_HTML_PATH = Path(__file__).resolve().parent.parent / "static" / "index.html"
@router.get("/", response_class=HTMLResponse, include_in_schema=False)
async def dashboard() -> HTMLResponse:
@router.get("/", include_in_schema=False)
async def dashboard() -> FileResponse:
"""Serve the operator dashboard. Static page that polls /health, /sources,
/stats and /jobs from the browser. Auth happens via the bearer header the
JS attaches to its fetches the dashboard route itself is unauthenticated
so an operator can open it in a browser and paste the token on demand."""
return HTMLResponse(content=_INDEX_HTML)
return FileResponse(_INDEX_HTML_PATH, media_type="text/html")