File size: 967 Bytes
6dd9bad 97f541f 6dd9bad 97f541f 6dd9bad 97f541f 6dd9bad | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001';
const ORG_ID = import.meta.env.VITE_ORG_ID as string | undefined;
export async function apiRequest<T = any>(endpoint: string, options: RequestInit = {}): Promise<T> {
const orgHeaders: Record<string, string> = ORG_ID ? { 'x-organization-id': ORG_ID } : {};
const res = await fetch(`${API_URL}${endpoint}`, {
...options,
headers: {
'Content-Type': 'application/json',
...orgHeaders,
...options.headers,
},
});
if (!res.ok) {
const errorData = await res.json().catch(() => ({}));
const error = new Error(errorData.error || 'Une erreur est survenue');
(error as any).status = res.status;
throw error;
}
return res.json();
}
export const apiClient = {
getStudent: (phone: string) => apiRequest(`/v1/student/me?phone=${phone}`),
// Future endpoints can be added here
};
|