From 50e9ad884c1fcf9149639a2afadc4a59948ff3ed Mon Sep 17 00:00:00 2001 From: happybell80 Date: Mon, 17 Nov 2025 18:15:24 +0900 Subject: [PATCH] docs: Update admin dashboard routing doc - link to standard deployment refactoring --- ..._admin_dashboard_routing_implementation.md | 120 ++++-------------- 1 file changed, 22 insertions(+), 98 deletions(-) diff --git a/journey/troubleshooting/251117_admin_dashboard_routing_implementation.md b/journey/troubleshooting/251117_admin_dashboard_routing_implementation.md index afbec20..2bc958e 100644 --- a/journey/troubleshooting/251117_admin_dashboard_routing_implementation.md +++ b/journey/troubleshooting/251117_admin_dashboard_routing_implementation.md @@ -23,102 +23,29 @@ robeing-gateway는 로빙 API 라우팅 전용으로 설계되어 `/admin` 경 ## 해결 방안 검토 -### 방안 1: nginx에서 직접 frontend-base로 프록시 -```nginx -location /admin { - proxy_pass http://localhost:8000; -} -``` +**참고**: 이 문서는 초기 구현 방식을 기록한 것이며, 이후 표준 배포 방식으로 전환되었습니다. 최신 구현 방식은 다음 문서를 참고하세요: +- **표준 배포 방식 전환**: `251117_admin_dashboard_standard_deployment_refactoring.md` -**문제점**: -- JWT 검증 불가 (인증 없이 접근 가능) -- frontend-base가 51124 robeing-monitor 데이터 조회 시 인증/UUID 변환 로직 중복 필요 +### 초기 구현 (폐기됨) +- Gateway가 frontend-base(localhost:8000)로 프록시하는 방식 +- FastAPI가 정적 HTML을 FileResponse로 서빙 -### 방안 2: Gateway에 `/admin` 라우팅 추가 (채택) -```python -@app.api_route("/admin/{path:path}", methods=["GET", "POST", "PUT", "DELETE"]) -async def admin_proxy( - path: str, - request: Request, - user_uuid: str = Depends(get_verified_user) -): - """Admin dashboard - proxy to frontend-base (51123:8000)""" - frontend_base_url = "http://localhost:8000" - target_url = f"{frontend_base_url}/admin/{path}" if path else f"{frontend_base_url}/admin" - - logger.info(f"Admin request from user {user_uuid} to {target_url}") - - async with httpx.AsyncClient() as client: - response = await client.request( - method=request.method, - url=target_url, - headers=dict(request.headers), - content=await request.body() - ) - - return Response( - content=response.content, - status_code=response.status_code, - headers=dict(response.headers) - ) -``` - -**장점**: -- JWT 검증 중앙화 유지 -- frontend-base가 Gateway의 인증/UUID 변환 활용 가능 -- 역할 분리 명확: Gateway(인증+라우팅), frontend-base(UI) +### 최종 채택 방식 +- nginx가 정적 파일(`/home/admin/admin-dashboard/frontend/dist/`)을 직접 서빙 +- FastAPI는 API만 처리 +- Gateway는 JWT 검증을 선택적으로 처리하여 HTML은 통과, API만 검증 --- -## 구현 내역 +## 구현 내역 (초기 구현 - 폐기됨) -### 1. robeing-gateway 코드 수정 +이 문서는 초기 구현 방식을 기록한 것이며, 이후 표준 배포 방식으로 전환되었습니다. -**파일**: `/home/admin/robeing-gateway/app/main.py` +**초기 구현 내용**: +- Gateway에 `/admin` 라우팅 추가하여 frontend-base로 프록시 +- FastAPI가 정적 HTML을 FileResponse로 서빙 -**변경 사항**: -1. Import 추가 (line 7): - ```python - from fastapi.responses import JSONResponse, Response - ``` - -2. `/admin` 라우팅 추가 (line 392-417): - - JWT 검증: `get_verified_user()` Dependency 적용 - - frontend-base(localhost:8000)로 프록시 - - 모든 HTTP 메서드 지원 (GET, POST, PUT, DELETE) - -### 2. Gateway 재시작 -```bash -cd /home/admin/robeing-gateway -docker compose down && docker compose up -d --build -``` - -### 3. 테스트 코드 작성 - -**파일**: `/home/admin/frontend-base/tests/test_admin_api.py` - -**테스트 케이스**: -1. Gateway `/admin` - JWT 없음 → 401 예상 -2. frontend-base `/health` → 200 OK -3. frontend-base `/admin` 직접 접근 → HTML 반환 - -**실행 결과**: -``` -=== Test 1: Gateway /admin without JWT (예상: 401) === -Status: 401 -✅ JWT 검증 작동 확인 - -=== Test 2: frontend-base /health === -Status: 200 -✅ frontend-base 정상 - -=== Test 3: frontend-base /admin (직접 접근) === -Status: 200 -Content-Type: text/html; charset=utf-8 -✅ Admin UI 정상 - -✅ 모든 테스트 통과 -``` +**최신 구현**: `251117_admin_dashboard_standard_deployment_refactoring.md` 참고 --- @@ -129,7 +56,7 @@ Content-Type: text/html; charset=utf-8 사용자 → nginx → robeing-gateway → 404 (라우팅 없음) ``` -### After (정상 동작) +### After (초기 구현 - 폐기됨) ``` 사용자 → nginx (:80/443) → robeing-gateway (:8100) ↓ JWT 검증 @@ -137,13 +64,7 @@ Content-Type: text/html; charset=utf-8 → frontend-base (:8000) → Admin UI 반환 ``` -### frontend-base가 robeing-monitor 데이터 조회 시 -``` -사용자 → Gateway (:8100/admin) - → frontend-base (:8000) - → Gateway (:8100/api/stats) ← JWT 재사용 - → robeing-monitor (:9024, 51124 서버) -``` +**최신 아키텍처**: `251117_admin_dashboard_standard_deployment_refactoring.md` 참고 --- @@ -184,15 +105,18 @@ curl -H "Authorization: Bearer YOUR_TOKEN" http://localhost:8100/admin - `/api/items` → robeing-monitor - `/admin` → frontend-base (51123:8000) -### 역할 분리 +### 역할 분리 (초기 설계 - 이후 변경됨) - **robeing-gateway**: 인증 + 라우팅 (코드 없는 프록시) -- **frontend-base**: 관리자 UI + 시스템 메트릭 대시보드 +- **frontend-base**: 관리자 UI + 시스템 메트릭 대시보드 (→ admin-dashboard로 변경) - **robeing-monitor**: 로빙 통계, 아이템 관리 (51124) +**최신 구조**: `251117_admin_dashboard_standard_deployment_refactoring.md` 참고 + --- ## 관련 문서 +- **표준 배포 방식 전환**: `251117_admin_dashboard_standard_deployment_refactoring.md` (최신) - **Gateway 아키텍처**: `/home/admin/DOCS/book/300_architecture/gateway_proxy_patterns.md` - **전체 시스템 구조**: `/home/admin/DOCS/book/300_architecture/310_전체_시스템_구조_컨테이너와_마이크로서비스.md` - **Gateway 구현 히스토리**: `/home/admin/DOCS/journey/troubleshooting/250809_happybell80_robing-gateway구현.md`