diff --git a/src/shared/apis/config.ts b/src/shared/apis/config.ts index b95b025..1d6d5ea 100644 --- a/src/shared/apis/config.ts +++ b/src/shared/apis/config.ts @@ -1,12 +1,3 @@ -const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL; -const apiTeamId = process.env.NEXT_PUBLIC_API_TEAM_ID; - -if (!apiBaseUrl) { - throw new Error('NEXT_PUBLIC_API_BASE_URL is not defined.'); -} -if (!apiTeamId) { - throw new Error('NEXT_PUBLIC_API_TEAM_ID is not defined.'); -} - -export const BASE_URL = apiBaseUrl; -export const TEAM_ID = apiTeamId; +// 빌드 시점이 아닌 실제 API 호출 시점에 유효성 검사를 수행하기 위해 undefined 허용 +export const BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL; +export const TEAM_ID = process.env.NEXT_PUBLIC_API_TEAM_ID; diff --git a/src/shared/apis/fetchApi.ts b/src/shared/apis/fetchApi.ts index 41496eb..0b707ed 100644 --- a/src/shared/apis/fetchApi.ts +++ b/src/shared/apis/fetchApi.ts @@ -1,7 +1,6 @@ import { BASE_URL, TEAM_ID } from './config'; const BODYLESS_METHODS = new Set(['GET', 'HEAD']); -const NORMALIZED_BASE_URL = normalizeBaseUrl(BASE_URL); const DEV_ACCESS_TOKEN = process.env.NEXT_PUBLIC_DEV_ACCESS_TOKEN; const IS_DEVELOPMENT = process.env.NODE_ENV === 'development'; @@ -14,8 +13,12 @@ function normalizePath(path: string) { } function buildApiUrl(path: string) { + // 실제 API 호출 시점에 환경변수 유효성 검사 + if (!BASE_URL) throw new Error('NEXT_PUBLIC_API_BASE_URL is not defined.'); + if (!TEAM_ID) throw new Error('NEXT_PUBLIC_API_TEAM_ID is not defined.'); + const relativePath = `${TEAM_ID}/${normalizePath(path)}`; - return new URL(relativePath, NORMALIZED_BASE_URL).toString(); + return new URL(relativePath, normalizeBaseUrl(BASE_URL)).toString(); } function getMethod(options: RequestInit) {