diff --git a/next.config.js b/next.config.js index aabb89d..2fb242c 100644 --- a/next.config.js +++ b/next.config.js @@ -19,6 +19,11 @@ const nextConfig = { source: '/api/proxy/:path*', destination: 'http://localhost:8084/api/:path*', }, + // Event Service API Proxy (8080 포트) + { + source: '/api/v1/events/:path*', + destination: 'http://localhost:8080/api/v1/events/:path*', + }, ] }, } diff --git a/src/app/api/v1/events/objectives/route.ts b/src/app/api/v1/events/objectives/route.ts new file mode 100644 index 0000000..369d57f --- /dev/null +++ b/src/app/api/v1/events/objectives/route.ts @@ -0,0 +1,66 @@ +import { NextRequest, NextResponse } from 'next/server'; + +/** + * Mock API: 이벤트 목적 선택 (Step 1) + * 백엔드 API가 준비될 때까지 사용하는 임시 Mock API + * + * POST /api/v1/events/objectives + */ +export async function POST(request: NextRequest) { + try { + const body = await request.json(); + const { objective } = body; + + // 백엔드 API 호출 시도 + const backendUrl = 'http://localhost:8080/api/v1/events/objectives'; + + try { + const backendResponse = await fetch(backendUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': request.headers.get('Authorization') || '', + }, + body: JSON.stringify(body), + }); + + // 백엔드가 정상 응답하면 그대로 반환 + if (backendResponse.ok) { + const data = await backendResponse.json(); + return NextResponse.json(data, { status: backendResponse.status }); + } + } catch (backendError) { + console.warn('⚠️ 백엔드 API 호출 실패, Mock 데이터 반환:', backendError); + } + + // 백엔드 실패 시 Mock 데이터 반환 + const mockEventId = `evt_${Date.now()}_${Math.random().toString(36).substring(7)}`; + + const mockResponse = { + success: true, + data: { + eventId: mockEventId, + objective, + status: 'DRAFT', + createdAt: new Date().toISOString(), + }, + message: '이벤트가 생성되었습니다 (Mock)', + }; + + console.log('🎭 Mock API Response:', mockResponse); + + return NextResponse.json(mockResponse, { status: 201 }); + } catch (error) { + console.error('❌ Mock API Error:', error); + + return NextResponse.json( + { + success: false, + errorCode: 'MOCK_ERROR', + message: 'Mock API 오류가 발생했습니다', + details: error instanceof Error ? error.message : 'Unknown error', + }, + { status: 500 } + ); + } +} diff --git a/src/entities/event/api/eventApi.ts b/src/entities/event/api/eventApi.ts index 6820d7a..a4e9277 100644 --- a/src/entities/event/api/eventApi.ts +++ b/src/entities/event/api/eventApi.ts @@ -29,11 +29,17 @@ const EVENT_HOST = process.env.NEXT_PUBLIC_EVENT_HOST || 'http://localhost:8080' /** * Event Service용 API 클라이언트 * Event Service는 별도 포트(8080)에서 실행되므로 별도 클라이언트 생성 + * + * 로컬 개발 환경: Next.js rewrites 프록시 사용 (CORS 회피) + * 프로덕션 환경: 환경 변수에서 직접 호스트 사용 */ import axios from 'axios'; +const isProduction = process.env.NODE_ENV === 'production'; +const API_BASE_URL = isProduction ? EVENT_HOST : ''; // 개발 환경에서는 상대 경로 사용 + const eventApiClient = axios.create({ - baseURL: EVENT_HOST, + baseURL: API_BASE_URL, timeout: 30000, headers: { 'Content-Type': 'application/json',