thermograph/app.py

37 lines
1.3 KiB
Python
Raw Normal View History

"""SSR frontend service: server-rendered content pages (content.py) plus the
static JS/CSS/PWA asset bundle. All climate data comes from the backend's
content API over HTTP (api_client.py) -- this process holds no data of its
own and does no polars/DB work.
"""
import mimetypes
from fastapi import FastAPI
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.staticfiles import StaticFiles
import content
import paths
# The PWA manifest is served as a static file; register its media type so
# StaticFiles labels it correctly (not in Python's default mimetypes map).
mimetypes.add_type("application/manifest+json", ".webmanifest")
app = FastAPI(title="Thermograph SSR", version="0.1.0")
# Compress every sizeable response, same threshold as the backend.
app.add_middleware(GZipMiddleware, minimum_size=1024)
@app.get("/healthz")
def healthz():
"""Liveness probe: the process is up and serving. Deliberately does no I/O
-- no call to the backend -- so it stays cheap and reliable for a tight
healthcheck interval. Readiness (backend reachable) is a separate concern."""
return {"status": "ok"}
# NOTE: "/" is not here -- the homepage is server-rendered by content.register().
content.register(app)
app.mount(content.BASE or "/", StaticFiles(directory=paths.STATIC_DIR), name="static")