빌드 시점에 NEXT_PUBLIC_API_URL 설정
This commit is contained in:
parent
c669374156
commit
1514af2383
|
|
@ -39,8 +39,10 @@ RUN npm ci && \
|
|||
COPY frontend/ ./
|
||||
|
||||
# Next.js 프로덕션 빌드 (린트 비활성화)
|
||||
# 빌드 시점에 환경변수 설정 (번들에 포함됨)
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_PUBLIC_API_URL="https://logistream.kpslp.kr:8080/api"
|
||||
RUN npm run build:no-lint
|
||||
|
||||
# ------------------------------
|
||||
|
|
|
|||
|
|
@ -64,7 +64,10 @@ export const useLogin = () => {
|
|||
// 로컬 스토리지에서 토큰 가져오기
|
||||
const token = localStorage.getItem("authToken");
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
||||
// API URL 동적 계산 (매번 호출 시마다)
|
||||
const apiBaseUrl = API_BASE_URL;
|
||||
|
||||
const response = await fetch(`${apiBaseUrl}${endpoint}`, {
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
|
|
|||
|
|
@ -32,11 +32,21 @@ const getApiBaseUrl = (): string => {
|
|||
}
|
||||
}
|
||||
|
||||
// 3. 기본값
|
||||
return "http://localhost:8080/api";
|
||||
// 3. 기본값 (서버사이드 빌드 시)
|
||||
return process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080/api";
|
||||
};
|
||||
|
||||
export const API_BASE_URL = getApiBaseUrl();
|
||||
// 매번 호출 시 동적으로 계산 (getter 함수)
|
||||
export const getAPIBaseURL = getApiBaseUrl;
|
||||
|
||||
// 하위 호환성을 위해 유지하되, 동적으로 계산되도록 수정
|
||||
let _cachedApiBaseUrl: string | null = null;
|
||||
export const API_BASE_URL = (() => {
|
||||
if (_cachedApiBaseUrl === null || typeof window !== "undefined") {
|
||||
_cachedApiBaseUrl = getApiBaseUrl();
|
||||
}
|
||||
return _cachedApiBaseUrl;
|
||||
})();
|
||||
|
||||
// 이미지 URL을 완전한 URL로 변환하는 함수
|
||||
export const getFullImageUrl = (imagePath: string): string => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue