Spaces:
Sleeping
Sleeping
ForStream Claude Opus 4.8 commited on
Commit ·
7eedd82
1
Parent(s): 72ceb13
Fix 404 루프: WEB_DIST 경로 robust 탐색 (/app/hf_app/web/dist 매칭)
Browse files- main.py가 /app/web/dist만 찾아 React dist(/app/hf_app/web/dist) 마운트 실패
- GET / 404 → HF 헬스체크 실패 → 재시작 루프 → address already in use
- 컨테이너/로컬 4개 후보 경로 탐색 + dist 미발견 시 fallback 루트 라우트
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- api/main.py +21 -3
api/main.py
CHANGED
|
@@ -252,9 +252,27 @@ def _call_gemma_col(question: str, context: str) -> AnswerCol:
|
|
| 252 |
|
| 253 |
|
| 254 |
# ============================================================
|
| 255 |
-
# 정적 파일 — React 빌드 결과
|
| 256 |
# ============================================================
|
| 257 |
-
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
from fastapi.staticfiles import StaticFiles
|
| 260 |
app.mount("/", StaticFiles(directory=str(WEB_DIST), html=True), name="web")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
|
| 254 |
# ============================================================
|
| 255 |
+
# 정적 파일 — React 빌드 결과 (컨테이너/로컬 경로 모두 탐색)
|
| 256 |
# ============================================================
|
| 257 |
+
_dist_candidates = [
|
| 258 |
+
HF_APP_DIR / "web" / "dist", # 로컬: active/hf_app/web/dist
|
| 259 |
+
HF_APP_DIR / "hf_app" / "web" / "dist", # 컨테이너 현 Dockerfile: /app/hf_app/web/dist
|
| 260 |
+
Path("/app/hf_app/web/dist"),
|
| 261 |
+
Path("/app/web/dist"),
|
| 262 |
+
]
|
| 263 |
+
WEB_DIST = next((p for p in _dist_candidates if p.exists()), None)
|
| 264 |
+
print(f"[startup] WEB_DIST = {WEB_DIST}")
|
| 265 |
+
if WEB_DIST is not None:
|
| 266 |
from fastapi.staticfiles import StaticFiles
|
| 267 |
app.mount("/", StaticFiles(directory=str(WEB_DIST), html=True), name="web")
|
| 268 |
+
else:
|
| 269 |
+
# dist 못 찾아도 헬스체크가 통과하도록 루트 라우트 제공 (재시작 루프 방지)
|
| 270 |
+
from fastapi.responses import HTMLResponse
|
| 271 |
+
|
| 272 |
+
@app.get("/")
|
| 273 |
+
def _root_fallback():
|
| 274 |
+
return HTMLResponse(
|
| 275 |
+
"<h1>LP출자 온톨로지 프로토타입 API</h1>"
|
| 276 |
+
"<p>프론트엔드 빌드(web/dist)를 찾지 못했습니다. API는 /api/* 에서 동작합니다.</p>"
|
| 277 |
+
f"<p>탐색 경로: {[str(p) for p in _dist_candidates]}</p>"
|
| 278 |
+
)
|