From d4775eee3d30a810a840f4582a964be3d6b90643 Mon Sep 17 00:00:00 2001 From: jieunsse Date: Sun, 22 Feb 2026 15:31:59 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B9=8C=EB=93=9C=20=EC=8B=9C=EC=A0=90?= =?UTF-8?q?=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 모듈 로드 시 throw하던 환경변수 검증을 fetchApi 호출 시점으로 이동하여 .env 없는 환경에서도 pnpm build가 통과되도록 수정. Co-Authored-By: Claude Sonnet 4.6 --- src/shared/apis/config.ts | 15 +++------------ src/shared/apis/fetchApi.ts | 7 +++++-- 2 files changed, 8 insertions(+), 14 deletions(-) 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) {