Spaces:
Sleeping
Sleeping
| 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(); | |
| } | |