From 38ef36aa75b989db5d85d65e1a5700a6adff9858 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 11 Apr 2026 17:27:46 +0200 Subject: [PATCH] Add test UI toggle and docs --- .env.example | 1 + README.md | 4 +++- app/config.py | 8 ++++++++ app/main.py | 5 +++++ docs/README.md | 4 ++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 0f430c0..bff394f 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ ENV=prod +FACE_LOCK_TEST_UI=true # Optional auth # FACE_LOCK_AUTH_TOKEN=change-me # FACE_LOCK_AUTH_HEADER=X-API-Key diff --git a/README.md b/README.md index 56aa1a5..54832c7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ FastAPI microservice that finds the primary subject in an image, draws a square ## UI -The Tailwind UI is always available at `/`. +The Tailwind test UI is available at `/` unless disabled with `FACE_LOCK_TEST_UI=false`. ## Auth @@ -40,6 +40,8 @@ pip install -r requirements.txt uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 ``` +Set `FACE_LOCK_TEST_UI=false` to disable the UI. + ## Docker ```bash diff --git a/app/config.py b/app/config.py index f568600..f423a66 100644 --- a/app/config.py +++ b/app/config.py @@ -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() diff --git a/app/main.py b/app/main.py index 824b9e2..3484f13 100644 --- a/app/main.py +++ b/app/main.py @@ -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( + "

face-lock

Test UI is disabled.

Open API docs

" + ) return HTMLResponse( """ diff --git a/docs/README.md b/docs/README.md index ed95ff1..7733139 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,6 +19,10 @@ face-lock is a FastAPI service that detects a primary subject, makes a square cr - `person` for full-body person detection - `subject` for general foreground subjects +## Test UI + +Set `FACE_LOCK_TEST_UI=false` to disable the `/` test UI. + ## Authentication Set `FACE_LOCK_AUTH_TOKEN` to require a header token.