2026-04-07 18:55:06 +09:00
|
|
|
export async function api(url, options = {}) {
|
2026-04-13 14:27:00 +09:00
|
|
|
const headers = { 'Content-Type': 'application/json', ...options.headers }
|
|
|
|
|
|
|
|
|
|
// 관리자 API에는 인증 헤더 자동 추가
|
|
|
|
|
if (url.startsWith('/api/admin')) {
|
|
|
|
|
const adminKey = localStorage.getItem('maple-admin-key')
|
|
|
|
|
if (adminKey) headers['x-admin-key'] = adminKey
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 18:55:06 +09:00
|
|
|
const res = await fetch(url, {
|
|
|
|
|
credentials: 'include',
|
|
|
|
|
...options,
|
2026-04-13 14:27:00 +09:00
|
|
|
headers,
|
2026-04-07 18:55:06 +09:00
|
|
|
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
const error = await res.json().catch(() => ({}))
|
|
|
|
|
throw new Error(error.error || `HTTP ${res.status}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res.json()
|
|
|
|
|
}
|