All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 19s
Browsers apply much more aggressive heuristic caching to a linked stylesheet than to the dynamically-rendered HTML that references it, so a CSS-only deploy could silently leave an already-open browser serving the old styles until a hard refresh -- exactly what made today's dashboard polish changes look broken while testing, until forcing a fresh fetch. Appends a content-hash query param computed once at startup. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
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},
|
|
)
|