This commit is contained in:
parent
af75b91371
commit
0455b1ee43
|
|
@ -1,7 +1,13 @@
|
||||||
import axios, { AxiosResponse, AxiosError } from "axios";
|
import axios, { AxiosResponse, AxiosError } from "axios";
|
||||||
|
|
||||||
// API URL 동적 설정 - 환경별 명확한 분리
|
// API URL 동적 설정 - 환경변수 우선 사용
|
||||||
const getApiBaseUrl = (): string => {
|
const getApiBaseUrl = (): string => {
|
||||||
|
// 1. 환경변수가 있으면 우선 사용
|
||||||
|
if (process.env.NEXT_PUBLIC_API_URL) {
|
||||||
|
return process.env.NEXT_PUBLIC_API_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 클라이언트 사이드에서 동적 설정
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
const currentHost = window.location.hostname;
|
const currentHost = window.location.hostname;
|
||||||
const currentPort = window.location.port;
|
const currentPort = window.location.port;
|
||||||
|
|
@ -13,18 +19,10 @@ const getApiBaseUrl = (): string => {
|
||||||
) {
|
) {
|
||||||
return "http://localhost:8080/api";
|
return "http://localhost:8080/api";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 서버 환경에서 localhost:5555 → 39.117.244.52:8080
|
|
||||||
if ((currentHost === "localhost" || currentHost === "127.0.0.1") && currentPort === "5555") {
|
|
||||||
return "http://39.117.244.52:8080/api";
|
|
||||||
}
|
|
||||||
|
|
||||||
// 기타 서버 환경 (내부/외부 IP): → 39.117.244.52:8080
|
|
||||||
return "http://39.117.244.52:8080/api";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 서버 사이드 렌더링 기본값
|
// 3. 기본값
|
||||||
return "http://39.117.244.52:8080/api";
|
return "http://localhost:8080/api";
|
||||||
};
|
};
|
||||||
|
|
||||||
export const API_BASE_URL = getApiBaseUrl();
|
export const API_BASE_URL = getApiBaseUrl();
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,9 @@ const nextConfig = {
|
||||||
|
|
||||||
// 환경 변수 (런타임에 읽기)
|
// 환경 변수 (런타임에 읽기)
|
||||||
env: {
|
env: {
|
||||||
// 프로덕션에서는 직접 백엔드 URL 사용, 개발환경에서는 프록시 사용
|
// 환경변수가 있으면 사용, 없으면 개발환경에서는 프록시 사용
|
||||||
NEXT_PUBLIC_API_URL:
|
NEXT_PUBLIC_API_URL:
|
||||||
process.env.NEXT_PUBLIC_API_URL ||
|
process.env.NEXT_PUBLIC_API_URL || (process.env.NODE_ENV === "production" ? "http://localhost:8080/api" : "/api"),
|
||||||
(process.env.NODE_ENV === "production" ? "http://39.117.244.52:8080/api" : "/api"),
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue