16 lines
513 B
JavaScript
16 lines
513 B
JavaScript
export const API_BASE_URL = process.env.PLANILLA_API_URL || "http://localhost:4000";
|
|
|
|
export async function fetchJSON(path, options = {}) {
|
|
const method = options.method || "GET";
|
|
console.log(`[API] ${method} ${API_BASE_URL}${path}`);
|
|
const res = await fetch(`${API_BASE_URL}${path}`, {
|
|
headers: { "Content-Type": "application/json" },
|
|
...options,
|
|
});
|
|
if (!res.ok) {
|
|
const txt = await res.text();
|
|
throw new Error(`API request failed (${res.status}): ${txt}`);
|
|
}
|
|
return res.json();
|
|
}
|