You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
706 B
TypeScript
16 lines
706 B
TypeScript
// frontend/lib/api.ts
|
|
export const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? "http://localhost:8000";
|
|
|
|
/** /api 프리픽스 경로를 절대 URL로. 예: apiUrl("/health") → http://localhost:8000/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<T>(path: string): Promise<T> {
|
|
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<T>;
|
|
}
|