| 1–14 |
docstring |
모듈 설명 — 계층 구조(transport/orchestration/result_shaping/observability), usage: python main.py --port 8765 |
| 16–23 |
import |
os, sys, argparse, asynccontextmanager, FastAPI, CORSMiddleware, APP_VERSION |
| 26–28 |
경로 설정 |
ROOT 자동 감지, sys.path 등록 |
| 31–34 |
dotenv |
.env UTF-8 로드(ImportError 시 무시) |
| 37–41 |
계층 임포트 |
rest_router, websocket_pipeline, make_metrics_app, get_logger |
| 43 |
ALLOWED_ORIGIN_REGEX |
^(null|https?://(127\.0\.0\.1|localhost)(:\d+)?)$ — CORS 정규식 |
| 47–49 |
lifespan |
asynccontextmanager — startup/shutdown 로그만 출력(DB 초기화 없음) |
| 53–67 |
FastAPI 앱 |
app = FastAPI(title, version, lifespan), CORS(allow_origins=[], allow_origin_regex로 localhost만 허용) |
| 70 |
라우터 등록 |
app.include_router(rest_router) |
| 71 |
WS 라우트 |
app.add_api_websocket_route("/ws/pipeline", websocket_pipeline) — 경로 /ws/pipeline |
| 74–76 |
Prometheus |
make_metrics_app() → /metrics 마운트(설치 시 활성) |
| 80–87 |
__main__ |
argparse로 --port(기본 8765)/--host(기본 127.0.0.1) 파싱, uvicorn.run() |