From fc5bd97ac1e9b4f76c6895c975c564d32488dc50 Mon Sep 17 00:00:00 2001 From: hyeonsu Date: Thu, 4 Sep 2025 15:18:25 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8F=99=EC=A0=81=20API=20URL=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/prod/docker-compose.backend.prod.yml | 2 +- frontend/lib/api/client.ts | 25 ++++++++++++++++++++- frontend/next.config.mjs | 4 ++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docker/prod/docker-compose.backend.prod.yml b/docker/prod/docker-compose.backend.prod.yml index 3cded048..85a0d189 100644 --- a/docker/prod/docker-compose.backend.prod.yml +++ b/docker/prod/docker-compose.backend.prod.yml @@ -13,7 +13,7 @@ services: - DATABASE_URL=postgresql://postgres:ph0909!!@39.117.244.52:11132/plm - JWT_SECRET=ilshin-plm-super-secret-jwt-key-2024 - JWT_EXPIRES_IN=24h - - CORS_ORIGIN=http://192.168.0.70:5555,http://39.117.244.52:5555 + - CORS_ORIGIN=http://192.168.0.70:5555,http://39.117.244.52:5555,http://localhost:9771 - CORS_CREDENTIALS=true - LOG_LEVEL=info restart: unless-stopped diff --git a/frontend/lib/api/client.ts b/frontend/lib/api/client.ts index 659a512a..b77aa173 100644 --- a/frontend/lib/api/client.ts +++ b/frontend/lib/api/client.ts @@ -1,6 +1,29 @@ import axios, { AxiosResponse, AxiosError } from "axios"; -export const API_BASE_URL = "http://39.117.244.52:8080/api"; +// API 기본 URL 동적 설정 - 접속 도메인에 따라 최적 API URL 결정 +const getApiBaseUrl = (): string => { + if (typeof window !== "undefined") { + const currentHost = window.location.hostname; + + // 로컬 개발환경 + if (currentHost === "localhost" || currentHost === "127.0.0.1") { + return "http://localhost:8080/api"; + } + // 내부 IP 접근 - 외부 IP로 통일 + else if (currentHost === "192.168.0.70") { + return "http://39.117.244.52:8080/api"; + } + // 외부 IP 접근 + else if (currentHost === "39.117.244.52") { + return "http://39.117.244.52:8080/api"; + } + } + + // 서버 사이드 렌더링이나 기본값 + return process.env.NEXT_PUBLIC_API_URL || "http://39.117.244.52:8080/api"; +}; + +export const API_BASE_URL = getApiBaseUrl(); // JWT 토큰 관리 유틸리티 const TokenManager = { diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index 50f2755d..9e986dab 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -41,9 +41,9 @@ const nextConfig = { ]; }, - // 환경 변수 (런타임에 읽기) - 내부 IP로 통일 + // 환경 변수 (런타임에 읽기) - 로컬 개발환경용 env: { - NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || "http://39.117.244.52:8080/api", + NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080/api", }, };