From 274507e2af4c3e24fb73edcfada01b055cf5af6b Mon Sep 17 00:00:00 2001 From: king Date: Sun, 24 May 2026 18:14:49 +0900 Subject: [PATCH] =?UTF-8?q?fix(returns):=20CORM=20=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=B4=EB=82=B4=EB=8A=94=20=EB=B0=98=ED=92=88=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20URL=20=EB=B0=8F=20=EC=9D=B8=EC=A6=9D=20=ED=97=A4?= =?UTF-8?q?=EB=8D=94=20=EA=B0=B1=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CS_RETURN_REQUEST_URL 기본값을 http://dbx-corm:8002/api/return/request 로 (docker 컨테이너 간 통신, 옛 127.0.0.1:8001 폐기). - httpx 요청에 X-Service-Token 헤더 첨부 (CORM AuthGuard 우회용). INTERNAL_SERVICE_TOKEN env 가 있을 때만 첨부. - .env.example 에 두 항목 안내 추가. --- .env.example | 8 ++++++++ app/routers/orders.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 8bf8646..d8f854e 100644 --- a/.env.example +++ b/.env.example @@ -44,6 +44,14 @@ TRUSTED_NAME_HEADER=X-Forwarded-User-Name # dbx-main 에서 인증된 사용자를 OMS DB 에 자동 등록할지 AUTO_PROVISION_USERS=1 + +# ===== 서비스 간 호출 (OMS → CORM 반품 신청) ===== +# CORM 컨테이너 이름 기반 URL. NPM 거치지 않고 docker network 로 직접 호출. +CS_RETURN_REQUEST_URL=http://dbx-corm:8002/api/return/request + +# 서비스 간 인증 토큰. OMS 와 CORM 양쪽 .env 에 동일한 값으로 박을 것. +# openssl rand -hex 32 로 생성. +INTERNAL_SERVICE_TOKEN=__paste-same-value-as-dbx-corm__ # 자동 등록 시 is_admin=True 로 만들 이메일(쉼표 구분) ADMIN_EMAILS=king@dbxcorp.co.kr diff --git a/app/routers/orders.py b/app/routers/orders.py index 3ab659a..184ed37 100644 --- a/app/routers/orders.py +++ b/app/routers/orders.py @@ -31,8 +31,11 @@ from app.search_utils import ( router = APIRouter() CS_RETURN_REQUEST_URL = os.getenv( "CS_RETURN_REQUEST_URL", - "http://127.0.0.1:8001/api/return/request", + "http://dbx-corm:8002/api/return/request", ) +# 서비스 간 호출 인증용 토큰 (양쪽 .env 에 같은 값으로 박는다). +# CORM 의 AuthGuard 가 이 헤더를 보고 세션 검사 우회. +INTERNAL_SERVICE_TOKEN = os.getenv("INTERNAL_SERVICE_TOKEN", "") # Global dict to hold upload progress. In a real world scenario this should be in Redis or DB. upload_progress_state = {} @@ -942,8 +945,11 @@ async def send_return_request( try: timeout = httpx.Timeout(connect=2.0, read=5.0, write=3.0, pool=2.0) + headers = {} + if INTERNAL_SERVICE_TOKEN: + headers["X-Service-Token"] = INTERNAL_SERVICE_TOKEN async with httpx.AsyncClient(timeout=timeout, trust_env=False) as client: - response = await client.post(CS_RETURN_REQUEST_URL, json=payload) + response = await client.post(CS_RETURN_REQUEST_URL, json=payload, headers=headers) response.raise_for_status() except httpx.HTTPStatusError as exc: response_text = exc.response.text[:1000] if exc.response is not None else ""