diff --git a/Dockerfile b/Dockerfile index eba3aeb0..609384d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,8 +39,10 @@ RUN npm ci && \ COPY frontend/ ./ # Next.js 프로덕션 빌드 (린트 비활성화) +# 빌드 시점에 환경변수 설정 (번들에 포함됨) ENV NEXT_TELEMETRY_DISABLED=1 ENV NODE_ENV=production +ENV NEXT_PUBLIC_API_URL="https://logistream.kpslp.kr:8080/api" RUN npm run build:no-lint # ------------------------------ diff --git a/frontend/hooks/useLogin.ts b/frontend/hooks/useLogin.ts index 09c32d5f..02837bc9 100644 --- a/frontend/hooks/useLogin.ts +++ b/frontend/hooks/useLogin.ts @@ -64,7 +64,10 @@ export const useLogin = () => { // 로컬 스토리지에서 토큰 가져오기 const token = localStorage.getItem("authToken"); - const response = await fetch(`${API_BASE_URL}${endpoint}`, { + // API URL 동적 계산 (매번 호출 시마다) + const apiBaseUrl = API_BASE_URL; + + const response = await fetch(`${apiBaseUrl}${endpoint}`, { credentials: "include", headers: { "Content-Type": "application/json", diff --git a/frontend/lib/api/client.ts b/frontend/lib/api/client.ts index 7279092e..d3afe83b 100644 --- a/frontend/lib/api/client.ts +++ b/frontend/lib/api/client.ts @@ -32,11 +32,21 @@ const getApiBaseUrl = (): string => { } } - // 3. 기본값 - return "http://localhost:8080/api"; + // 3. 기본값 (서버사이드 빌드 시) + return process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080/api"; }; -export const API_BASE_URL = getApiBaseUrl(); +// 매번 호출 시 동적으로 계산 (getter 함수) +export const getAPIBaseURL = getApiBaseUrl; + +// 하위 호환성을 위해 유지하되, 동적으로 계산되도록 수정 +let _cachedApiBaseUrl: string | null = null; +export const API_BASE_URL = (() => { + if (_cachedApiBaseUrl === null || typeof window !== "undefined") { + _cachedApiBaseUrl = getApiBaseUrl(); + } + return _cachedApiBaseUrl; +})(); // 이미지 URL을 완전한 URL로 변환하는 함수 export const getFullImageUrl = (imagePath: string): string => {