const API_BASE_URL = import.meta.env.VITE_API_BASE_URL export async function apiFetch(endpoint, options = {}) { const token = sessionStorage.getItem('token') const defaultHeaders = { 'ngrok-skip-browser-warning': 'true', 'Content-Type': 'application/json', ...options.headers, } if (token) { defaultHeaders['Authorization'] = `Bearer ${token}` } const response = await fetch(`${API_BASE_URL}${endpoint}`, { ...options, headers: defaultHeaders, }) if (!response.ok) { // Try to parse the error response body from the server const errorData = await response.json() throw new Error(errorData.message || `API call failed with status: ${response.status}`) } if (response.status === 204) { return null } return response.json() }