From 2d6b0fc7ceaad90d97b41fc2e2e46bd1155dc4ea Mon Sep 17 00:00:00 2001 From: hyeonsu Date: Thu, 4 Sep 2025 11:46:42 +0900 Subject: [PATCH] =?UTF-8?q?ip=20adress=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend-node/src/app.ts | 2 +- backend-node/src/config/environment.ts | 4 ++-- frontend/lib/api/client.ts | 27 ++++++++++++++++++++++++-- frontend/next.config.mjs | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/backend-node/src/app.ts b/backend-node/src/app.ts index 3b281d19..be12bcad 100644 --- a/backend-node/src/app.ts +++ b/backend-node/src/app.ts @@ -29,7 +29,7 @@ app.use(express.urlencoded({ extended: true, limit: "10mb" })); // CORS 설정 app.use( cors({ - origin: config.cors.origin, + origin: config.cors.origin.split(',').map(url => url.trim()), credentials: true, methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"], allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"], diff --git a/backend-node/src/config/environment.ts b/backend-node/src/config/environment.ts index be936f76..56478ae3 100644 --- a/backend-node/src/config/environment.ts +++ b/backend-node/src/config/environment.ts @@ -82,8 +82,8 @@ const config: Config = { // CORS 설정 cors: { - origin: process.env.CORS_ORIGIN || "http://localhost:9771", - credentials: process.env.CORS_CREDENTIALS === "true", + origin: process.env.CORS_ORIGIN || "http://localhost:9771,http://192.168.0.70:5555,http://39.117.244.52:5555", + credentials: process.env.CORS_CREDENTIALS === "true" || true, }, // 로깅 설정 diff --git a/frontend/lib/api/client.ts b/frontend/lib/api/client.ts index e3eef389..5404774a 100644 --- a/frontend/lib/api/client.ts +++ b/frontend/lib/api/client.ts @@ -1,7 +1,30 @@ import axios, { AxiosResponse, AxiosError } from "axios"; -// API 기본 URL 설정 -export const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080/api"; +// API 기본 URL 동적 설정 (클라이언트 사이드에서 현재 도메인 기반으로 결정) +const getApiBaseUrl = (): string => { + if (typeof window !== 'undefined') { + const currentHost = window.location.hostname; + const currentPort = window.location.port; + + // 외부 IP로 접근한 경우 + if (currentHost === '39.117.244.52') { + return 'http://39.117.244.52:8080/api'; + } + // 내부 IP로 접근한 경우 + else if (currentHost === '192.168.0.70') { + return 'http://192.168.0.70:8080/api'; + } + // localhost로 접근한 경우 + else if (currentHost === 'localhost' || currentHost === '127.0.0.1') { + return 'http://localhost: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 286faf4a..5323571a 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -43,7 +43,7 @@ const nextConfig = { // 환경 변수 (런타임에 읽기) env: { - NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || "http://192.168.0.70:8080/api", + NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || "http://39.117.244.52:8080/api", }, };