Add test UI toggle and docs
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
ENV=prod
|
ENV=prod
|
||||||
|
FACE_LOCK_TEST_UI=true
|
||||||
# Optional auth
|
# Optional auth
|
||||||
# FACE_LOCK_AUTH_TOKEN=change-me
|
# FACE_LOCK_AUTH_TOKEN=change-me
|
||||||
# FACE_LOCK_AUTH_HEADER=X-API-Key
|
# FACE_LOCK_AUTH_HEADER=X-API-Key
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ FastAPI microservice that finds the primary subject in an image, draws a square
|
|||||||
|
|
||||||
## UI
|
## UI
|
||||||
|
|
||||||
The Tailwind UI is always available at `/`.
|
The Tailwind test UI is available at `/` unless disabled with `FACE_LOCK_TEST_UI=false`.
|
||||||
|
|
||||||
## Auth
|
## Auth
|
||||||
|
|
||||||
@@ -40,6 +40,8 @@ pip install -r requirements.txt
|
|||||||
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
|
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Set `FACE_LOCK_TEST_UI=false` to disable the UI.
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -6,9 +6,17 @@ from dotenv import load_dotenv
|
|||||||
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)
|
@dataclass(frozen=True)
|
||||||
class Settings:
|
class Settings:
|
||||||
env: str = os.getenv("ENV", "prod").strip().lower()
|
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_token: str = os.getenv("FACE_LOCK_AUTH_TOKEN", "").strip()
|
||||||
auth_header_name: str = os.getenv("FACE_LOCK_AUTH_HEADER", "X-API-Key").strip()
|
auth_header_name: str = os.getenv("FACE_LOCK_AUTH_HEADER", "X-API-Key").strip()
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ def health():
|
|||||||
return {
|
return {
|
||||||
"ok": True,
|
"ok": True,
|
||||||
"env": settings.env,
|
"env": settings.env,
|
||||||
|
"test_ui_enabled": settings.test_ui_enabled,
|
||||||
"auth_enabled": settings.auth_enabled,
|
"auth_enabled": settings.auth_enabled,
|
||||||
"auth_header": settings.auth_header_name if settings.auth_enabled else None,
|
"auth_header": settings.auth_header_name if settings.auth_enabled else None,
|
||||||
}
|
}
|
||||||
@@ -31,6 +32,10 @@ def health():
|
|||||||
|
|
||||||
@app.get("/", response_class=HTMLResponse)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
def index():
|
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(
|
return HTMLResponse(
|
||||||
"""
|
"""
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
|||||||
@@ -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
|
- `person` for full-body person detection
|
||||||
- `subject` for general foreground subjects
|
- `subject` for general foreground subjects
|
||||||
|
|
||||||
|
## Test UI
|
||||||
|
|
||||||
|
Set `FACE_LOCK_TEST_UI=false` to disable the `/` test UI.
|
||||||
|
|
||||||
## Authentication
|
## Authentication
|
||||||
|
|
||||||
Set `FACE_LOCK_AUTH_TOKEN` to require a header token.
|
Set `FACE_LOCK_AUTH_TOKEN` to require a header token.
|
||||||
|
|||||||
Reference in New Issue
Block a user