from fastapi import APIRouter, Request from fastapi.responses import JSONResponse from fastapi.templating import Jinja2Templates from app.services import diagnostics router = APIRouter(tags=["health"]) templates = Jinja2Templates(directory="app/templates") @router.get("/health") async def health(): """Unauthenticated JSON health check. 200 when everything critical is configured, 503 when something critical is missing so an uptime monitor notices. The body always lists every check either way.""" result = diagnostics.summary() status_code = 200 if result["status"] == "ok" else 503 return JSONResponse(result, status_code=status_code) @router.get("/setup") async def setup(request: Request): """Unauthenticated, human-readable version of the same checks, so a fresh operator can see what still needs configuring before login works.""" result = diagnostics.summary() return templates.TemplateResponse( request, "setup.html", {"status": result["status"], "checks": result["checks"]}, )