from __future__ import annotations import hashlib from pathlib import Path from fastapi import APIRouter, Request from fastapi.templating import Jinja2Templates from app.config import settings router = APIRouter() templates = Jinja2Templates(directory="app/web/templates") def _asset_version(path: str) -> str: """A short hash of a static asset's content, used to cache-bust it in templates -- browsers apply much more aggressive heuristic caching to linked CSS/JS than to the dynamically-rendered HTML that references it, so without this, a deploy that only changes style.css can leave a visitor's browser silently serving the old stylesheet until they hard-refresh. Computed once at startup since the file is baked into the image and won't change while this process is running.""" try: return hashlib.md5(Path(path).read_bytes()).hexdigest()[:8] except FileNotFoundError: return "0" templates.env.globals["static_version"] = _asset_version("app/static/css/style.css") @router.get("/") def dashboard(request: Request): return templates.TemplateResponse(request, "dashboard.html", {}) @router.get("/plans") def plans_page(request: Request): return templates.TemplateResponse(request, "plans.html", {}) @router.get("/settings") def settings_page(request: Request): return templates.TemplateResponse( request, "settings.html", {"use_mock_isolarcloud": settings.use_mock_isolarcloud, "isolarcloud_auth_mode": settings.isolarcloud_auth_mode}, )