fix: configure frontend services for environment API URLs
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||
const BASE = `${API_URL}/api/admin`
|
||||
|
||||
function authHeaders() {
|
||||
return {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -12,35 +15,35 @@ function apiError(message, status) {
|
||||
}
|
||||
|
||||
export async function getStatsApi() {
|
||||
const res = await fetch('/api/admin/stats', { headers: authHeaders() })
|
||||
const res = await fetch(`${BASE}/stats`, { headers: authHeaders() })
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw apiError(data.message || 'Erreur stats.', res.status)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getUsersApi() {
|
||||
const res = await fetch('/api/admin/users', { headers: authHeaders() })
|
||||
const res = await fetch(`${BASE}/users`, { headers: authHeaders() })
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw apiError(data.message || 'Erreur utilisateurs.', res.status)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function drawWinnerApi() {
|
||||
const res = await fetch('/api/admin/draw', { method: 'POST', headers: authHeaders() })
|
||||
const res = await fetch(`${BASE}/draw`, { method: 'POST', headers: authHeaders() })
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw apiError(data.message || 'Erreur tirage.', res.status)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getEmailingContactsApi() {
|
||||
const res = await fetch('/api/admin/emailing', { headers: authHeaders() })
|
||||
const res = await fetch(`${BASE}/emailing`, { headers: authHeaders() })
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw apiError(data.message || 'Erreur contacts emailing.', res.status)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getWinnerApi() {
|
||||
const res = await fetch('/api/admin/draw', { headers: authHeaders() })
|
||||
const res = await fetch(`${BASE}/draw`, { headers: authHeaders() })
|
||||
if (res.status === 404) return null
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw apiError(data.message || 'Erreur gagnant.', res.status)
|
||||
|
||||
Reference in New Issue
Block a user