Add test UI toggle and docs

This commit is contained in:
2026-04-11 17:27:46 +02:00
parent 09119e8c0e
commit 38ef36aa75
5 changed files with 21 additions and 1 deletions

View File

@@ -6,9 +6,17 @@ from dotenv import load_dotenv
load_dotenv()
def _env_bool(name: str, default: bool = False) -> bool:
value = os.getenv(name)
if value is None:
return default
return value.strip().lower() in {"1", "true", "yes", "on"}
@dataclass(frozen=True)
class Settings:
env: str = os.getenv("ENV", "prod").strip().lower()
test_ui_enabled: bool = _env_bool("FACE_LOCK_TEST_UI", True)
auth_token: str = os.getenv("FACE_LOCK_AUTH_TOKEN", "").strip()
auth_header_name: str = os.getenv("FACE_LOCK_AUTH_HEADER", "X-API-Key").strip()

View File

@@ -24,6 +24,7 @@ def health():
return {
"ok": True,
"env": settings.env,
"test_ui_enabled": settings.test_ui_enabled,
"auth_enabled": settings.auth_enabled,
"auth_header": settings.auth_header_name if settings.auth_enabled else None,
}
@@ -31,6 +32,10 @@ def health():
@app.get("/", response_class=HTMLResponse)
def index():
if not settings.test_ui_enabled:
return HTMLResponse(
"<!doctype html><html><body style='font-family:sans-serif;background:#0f172a;color:#e2e8f0;padding:2rem'><h1>face-lock</h1><p>Test UI is disabled.</p><p><a href='/docs' style='color:#67e8f9'>Open API docs</a></p></body></html>"
)
return HTMLResponse(
"""
<!doctype html>