From 1514af23831a0c5e3e0e24da7872d2871024edb1 Mon Sep 17 00:00:00 2001 From: dohyeons Date: Tue, 11 Nov 2025 17:49:41 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=8C=EB=93=9C=20=EC=8B=9C=EC=A0=90?= =?UTF-8?q?=EC=97=90=20NEXT=5FPUBLIC=5FAPI=5FURL=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 ++ frontend/hooks/useLogin.ts | 5 ++++- frontend/lib/api/client.ts | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) 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 => {