fix: configure frontend services for environment API URLs
This commit is contained in:
@@ -10,7 +10,7 @@ const options = {
|
|||||||
},
|
},
|
||||||
servers: [
|
servers: [
|
||||||
{
|
{
|
||||||
url: "http://localhost:5000",
|
url: process.env.API_PUBLIC_URL || "http://localhost:5000",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||||
|
const BASE = `${API_URL}/api/admin`
|
||||||
|
|
||||||
function authHeaders() {
|
function authHeaders() {
|
||||||
return {
|
return {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -12,35 +15,35 @@ function apiError(message, status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getStatsApi() {
|
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()
|
const data = await res.json()
|
||||||
if (!res.ok) throw apiError(data.message || 'Erreur stats.', res.status)
|
if (!res.ok) throw apiError(data.message || 'Erreur stats.', res.status)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUsersApi() {
|
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()
|
const data = await res.json()
|
||||||
if (!res.ok) throw apiError(data.message || 'Erreur utilisateurs.', res.status)
|
if (!res.ok) throw apiError(data.message || 'Erreur utilisateurs.', res.status)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function drawWinnerApi() {
|
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()
|
const data = await res.json()
|
||||||
if (!res.ok) throw apiError(data.message || 'Erreur tirage.', res.status)
|
if (!res.ok) throw apiError(data.message || 'Erreur tirage.', res.status)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getEmailingContactsApi() {
|
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()
|
const data = await res.json()
|
||||||
if (!res.ok) throw apiError(data.message || 'Erreur contacts emailing.', res.status)
|
if (!res.ok) throw apiError(data.message || 'Erreur contacts emailing.', res.status)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getWinnerApi() {
|
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
|
if (res.status === 404) return null
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
if (!res.ok) throw apiError(data.message || 'Erreur gagnant.', res.status)
|
if (!res.ok) throw apiError(data.message || 'Erreur gagnant.', res.status)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const BASE = '/api/auth'
|
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||||
|
const BASE = `${API_URL}/api/auth
|
||||||
|
|
||||||
function apiError(message, status) {
|
function apiError(message, status) {
|
||||||
const err = new Error(message)
|
const err = new Error(message)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const BASE = '/api/employee'
|
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||||
|
const BASE = `${API_URL}/api/employee`
|
||||||
|
|
||||||
function authHeaders() {
|
function authHeaders() {
|
||||||
const token = localStorage.getItem('token')
|
const token = localStorage.getItem('token')
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||||
|
const BASE = `${API_URL}/api/game`
|
||||||
|
|
||||||
|
|
||||||
function apiError(message, status) {
|
function apiError(message, status) {
|
||||||
const err = new Error(message)
|
const err = new Error(message)
|
||||||
err.status = status
|
err.status = status
|
||||||
@@ -6,7 +10,7 @@ function apiError(message, status) {
|
|||||||
|
|
||||||
export async function myGainsApi() {
|
export async function myGainsApi() {
|
||||||
const token = localStorage.getItem('token')
|
const token = localStorage.getItem('token')
|
||||||
const res = await fetch('/api/game/my-gains', {
|
const res = await fetch(`${BASE}/my-gains`, {
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
})
|
})
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
@@ -16,7 +20,7 @@ export async function myGainsApi() {
|
|||||||
|
|
||||||
export async function participateApi(code) {
|
export async function participateApi(code) {
|
||||||
const token = localStorage.getItem('token')
|
const token = localStorage.getItem('token')
|
||||||
const res = await fetch('/api/game/participate', {
|
const res = await fetch(`${BASE}/participate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
Reference in New Issue
Block a user