fix: configure frontend services for environment API URLs

This commit is contained in:
2026-08-17 12:27:14 +00:00
parent 09e6c86ca0
commit 3e12fa2d01
5 changed files with 20 additions and 11 deletions

View File

@@ -10,7 +10,7 @@ const options = {
},
servers: [
{
url: "http://localhost:5000",
url: process.env.API_PUBLIC_URL || "http://localhost:5000",
},
],
components: {
@@ -26,4 +26,4 @@ const options = {
apis: ["./src/routes/*.js"],
};
module.exports = swaggerJsdoc(options);
module.exports = swaggerJsdoc(options);

View File

@@ -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)

View File

@@ -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) {
const err = new Error(message)

View File

@@ -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() {
const token = localStorage.getItem('token')

View File

@@ -1,3 +1,7 @@
const API_URL = import.meta.env.VITE_API_URL || ''
const BASE = `${API_URL}/api/game`
function apiError(message, status) {
const err = new Error(message)
err.status = status
@@ -6,7 +10,7 @@ function apiError(message, status) {
export async function myGainsApi() {
const token = localStorage.getItem('token')
const res = await fetch('/api/game/my-gains', {
const res = await fetch(`${BASE}/my-gains`, {
headers: { Authorization: `Bearer ${token}` },
})
const data = await res.json()
@@ -16,7 +20,7 @@ export async function myGainsApi() {
export async function participateApi(code) {
const token = localStorage.getItem('token')
const res = await fetch('/api/game/participate', {
const res = await fetch(`${BASE}/participate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',