Configuration portable : chemins relatifs et API dynamique

This commit is contained in:
2026-02-05 18:30:35 +01:00
parent 8b905dc9b3
commit 53869a6626
6 changed files with 195 additions and 16 deletions

View File

@@ -1,7 +1,20 @@
// Configuration API - Déterminer l'URL de base
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
? 'http://localhost:4001/api'
: `http://${window.location.hostname}:4001/api`;
// Configuration API - Détection automatique de l'URL de base
// Fonctionne avec localhost, IP publique, ou nom de domaine
const API_URL = (() => {
const protocol = window.location.protocol; // http: ou https:
const hostname = window.location.hostname; // IP ou domaine
const port = '4001'; // Port du backend
// Si on accède depuis le même port que le backend (mode production intégré)
if (window.location.port === port) {
return `${protocol}//${hostname}:${port}/api`;
}
// Mode développement ou accès via différent port
return `${protocol}//${hostname}:${port}/api`;
})();
console.log('API URL configurée:', API_URL);
// State
let currentUser = null;