Move page routes to routers/dashboard.py, the content-negotiated error handler to errors.py (register_error_handlers), and the dev css-mtime endpoint to routers/dev.py (included only when debug). main.py shrinks to lifespan + wiring + the / landing route. Dashboard repos now load lazily via an htmx fragment so a slow/unreachable Forgejo instance never blocks first paint; Forgejo html_url is sanitized against non-http(s) schemes before rendering into href.
19 lines
558 B
Python
19 lines
558 B
Python
"""Development-only endpoints. Included on the app only when debug is enabled."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from fastapi import APIRouter
|
|
|
|
router = APIRouter(prefix="/api/dev", tags=["dev"])
|
|
|
|
_CSS_OUTPUT = Path(__file__).parent.parent / "static" / "css" / "output.css"
|
|
|
|
|
|
@router.get("/css-mtime")
|
|
async def css_mtime() -> dict:
|
|
"""Report the built CSS file's mtime so the browser can live-reload on change."""
|
|
if _CSS_OUTPUT.exists():
|
|
return {"mtime": _CSS_OUTPUT.stat().st_mtime}
|
|
return {"mtime": 0}
|