Configuration portable : chemins relatifs et API dynamique
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user