underrate's picture
Initial commit
34ed5b1 verified
Raw
History Blame Contribute Delete
548 Bytes
export const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:5000/api';
export async function fetchAPI(endpoint: string, options: RequestInit = {}) {
const res = await fetch(`${API_URL}${endpoint}`, {
...options,
headers: {
'Content-Type': 'application/json',
...options.headers,
},
});
if (!res.ok) {
const error = await res.json().catch(() => ({}));
throw new Error(error.error || 'An error occurred');
}
return res.json();
}