// frontend/lib/api.ts export const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? (typeof window === "undefined" ? "http://localhost:31800" : ""); /** /api 프리픽스 경로를 절대 URL로. 예: apiUrl("/health") → http://localhost:31800/api/health */ export function apiUrl(path: string): string { const clean = path.startsWith("/") ? path : `/${path}`; return `${API_BASE}/api${clean}`; } /** 얇은 fetch 래퍼 — Phase 2 이후 본격 사용. Phase 0 스모크용 health 핑. */ export async function getJson(path: string): Promise { const res = await fetch(apiUrl(path), { headers: { Accept: "application/json" } }); if (!res.ok) throw new Error(`GET ${path} → ${res.status}`); return res.json() as Promise; }