동적 API URL 설정
This commit is contained in:
parent
30b56b1acf
commit
fc5bd97ac1
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue