"""Production ASGI entrypoint: wraps app.main:app and hides API docs by default. Serve with: python -m uvicorn app.asgi:application --port 8000 Set RESUME_AGENT_API_DOCS=1 to expose /docs, /redoc and /openapi.json. """ from __future__ import annotations import os from typing import Any from .main import app _DOC_PATHS = {"/docs", "/docs/oauth2-redirect", "/redoc", "/openapi.json"} def _docs_enabled() -> bool: return os.getenv("RESUME_AGENT_API_DOCS", "").strip().lower() in {"1", "true", "on"} class _DocsGate: """ASGI wrapper returning 404 for API-doc routes unless explicitly enabled.""" def __init__(self, wrapped: Any) -> None: self.wrapped = wrapped async def __call__(self, scope: dict[str, Any], receive: Any, send: Any) -> None: if scope.get("type") == "http" and scope.get("path") in _DOC_PATHS and not _docs_enabled(): payload = b'{"detail":"Not Found"}' await send({ "type": "http.response.start", "status": 404, "headers": [(b"content-type", b"application/json"), (b"content-length", str(len(payload)).encode())], }) await send({"type": "http.response.body", "body": payload}) return await self.wrapped(scope, receive, send) application = _DocsGate(app)