diff --git a/apps/api/app/deps.py b/apps/api/app/deps.py index 3b70764..f18301a 100644 --- a/apps/api/app/deps.py +++ b/apps/api/app/deps.py @@ -63,10 +63,12 @@ async def get_current_principal( prod 에선 session_cookie 검증 실패 시 무조건 401. """ if not session_cookie: - raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail="not authenticated", - ) + # dev 환경에선 쿠키 없어도 더미 학습자로 통과(로컬 라이브 테스트). prod 는 무조건 401. + if get_settings().environment != "dev": + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="not authenticated", + ) # TODO: Redis 세션 룩업. 아래는 개발 스텁. return Principal(user_id="dev-user", role=Role.LEARNER, cohort_ids=[]) diff --git a/apps/api/app/main.py b/apps/api/app/main.py index 441e06d..1795659 100644 --- a/apps/api/app/main.py +++ b/apps/api/app/main.py @@ -25,14 +25,26 @@ from .routes import voice as voice_routes @asynccontextmanager async def lifespan(app: FastAPI): - """startup: DB 풀 + 엔진 클라이언트 / shutdown: 정리.""" - await init_pool() + """startup: DB 풀 + 엔진 클라이언트 / shutdown: 정리. + + DB 미가용(Docker off / NAS 연결불가)이면 store 인메모리 폴백으로 degraded 기동한다. + """ + try: + await init_pool() + except Exception as exc: # DB 없어도 store 폴백으로 1턴 동작 (dev/로컬) + import logging + logging.getLogger("uvicorn.error").warning( + "DB 풀 초기화 실패 — store 인메모리 폴백으로 degraded 기동: %s", exc + ) await engine_client.startup() try: yield finally: await engine_client.shutdown() - await close_pool() + try: + await close_pool() + except Exception: + pass app = FastAPI(