From 0d629a27a6f860b396df24cc0075d1e2f018e71c Mon Sep 17 00:00:00 2001 From: hyeonsu Date: Thu, 4 Sep 2025 15:39:29 +0900 Subject: [PATCH] =?UTF-8?q?=EC=84=9C=EB=B2=84/=EB=A1=9C=EC=BB=AC=20?= =?UTF-8?q?=EB=82=98=EB=88=A0=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/lib/api/client.ts | 46 ++++++++------------------------------ 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/frontend/lib/api/client.ts b/frontend/lib/api/client.ts index 6f448a9c..f0bc3321 100644 --- a/frontend/lib/api/client.ts +++ b/frontend/lib/api/client.ts @@ -1,40 +1,24 @@ import axios, { AxiosResponse, AxiosError } from "axios"; -// API 기본 URL 동적 설정 - 런타임에 결정 +// API URL 동적 설정 - 환경별 명확한 분리 const getApiBaseUrl = (): string => { - // 브라우저 환경에서만 동적 결정 if (typeof window !== "undefined") { const currentHost = window.location.hostname; - console.log("🌐 현재 접속 호스트:", currentHost); - // 로컬 개발환경 + // 로컬 개발환경: localhost:9771 → localhost:8080 if (currentHost === "localhost" || currentHost === "127.0.0.1") { - console.log("🏠 로컬 개발환경 감지 → localhost:8080/api"); return "http://localhost:8080/api"; } - // 내부 IP 접근 - 외부 IP로 통일 - else if (currentHost === "192.168.0.70") { - console.log("🏢 내부 IP 접근 감지 → 39.117.244.52:8080/api"); - return "http://39.117.244.52:8080/api"; - } - // 외부 IP 접근 - else if (currentHost === "39.117.244.52") { - console.log("🌍 외부 IP 접근 감지 → 39.117.244.52:8080/api"); - return "http://39.117.244.52:8080/api"; - } + + // 서버 환경 (내부/외부 IP 모두): → 39.117.244.52:8080 + return "http://39.117.244.52:8080/api"; } - // 서버 사이드 렌더링이나 기본값 - 외부 IP 사용 - console.log("🖥️ 서버 사이드 렌더링 → 39.117.244.52:8080/api"); + // 서버 사이드 렌더링 기본값 return "http://39.117.244.52:8080/api"; }; -// 런타임에 동적으로 결정되도록 함수로 변경 -const getDynamicApiBaseUrl = () => { - return getApiBaseUrl(); -}; - -export const API_BASE_URL = getDynamicApiBaseUrl(); +export const API_BASE_URL = getApiBaseUrl(); // JWT 토큰 관리 유틸리티 const TokenManager = { @@ -55,8 +39,9 @@ const TokenManager = { }, }; -// Axios 인스턴스 생성 - 동적 baseURL 설정 +// Axios 인스턴스 생성 export const apiClient = axios.create({ + baseURL: API_BASE_URL, timeout: 10000, headers: { "Content-Type": "application/json", @@ -64,19 +49,6 @@ export const apiClient = axios.create({ withCredentials: true, // 쿠키 포함 }); -// 매 요청마다 baseURL을 동적으로 설정 -apiClient.interceptors.request.use( - (config) => { - // 동적 baseURL 설정 - const dynamicBaseURL = getApiBaseUrl(); - config.baseURL = dynamicBaseURL; - console.log("🔗 동적 API URL 설정:", dynamicBaseURL); - - return config; - }, - (error) => Promise.reject(error), -); - // 요청 인터셉터 apiClient.interceptors.request.use( (config) => {