📝 Consolidation documentation : suppression redondances, config centralisée
This commit is contained in:
111
MODIFICATIONS.md
111
MODIFICATIONS.md
@@ -1,83 +1,66 @@
|
||||
# 📝 Résumé des Modifications - Configuration Portable
|
||||
# 📝 Modifications Techniques
|
||||
|
||||
Ce document résume les modifications apportées pour rendre le déploiement portable et simplifié.
|
||||
Résumé des changements pour portabilité et simplification.
|
||||
|
||||
## 🎯 Objectifs Atteints
|
||||
## ✅ Objectifs Atteints
|
||||
|
||||
✅ **Chemins relatifs** : Plus de chemins absolus du type `/home/innotex/...`
|
||||
✅ **Variables d'environnement** : Configuration centralisée via fichiers `.env`
|
||||
✅ **Détection automatique de l'hôte** : L'API fonctionne avec localhost, IP ou domaine
|
||||
✅ **Déploiement unifié** : Un seul script pour tout démarrer
|
||||
✅ **Portabilité totale** : Fonctionne sur n'importe quelle machine Linux
|
||||
- ✅ Chemins relatifs (100% portable)
|
||||
- ✅ Configuration centralisée (shared.env)
|
||||
- ✅ Détection automatique API
|
||||
- ✅ Synchronisation Git automatique
|
||||
- ✅ Déploiement unifié
|
||||
|
||||
## 📁 Fichiers Créés
|
||||
## 🔑 Changements Clés
|
||||
|
||||
### Dossier racine (`Serveur NationsGlory/`)
|
||||
- **`deploy.sh`** : Script principal de déploiement (démarre MC + Web)
|
||||
- **`stop.sh`** : Script d'arrêt de tous les services
|
||||
- **`check-config.sh`** : Script de vérification de configuration
|
||||
- **`README.md`** : Documentation principale du projet
|
||||
- **`QUICKSTART.md`** : Guide de démarrage rapide
|
||||
### 1. Configuration Centralisée
|
||||
|
||||
### Application Web (`WebNationsGlory_ServeurBuild_Red/`)
|
||||
- **`.env.example`** : Template de configuration avec toutes les variables
|
||||
- **`nginx.conf.example`** : Configuration nginx pour production avec SSL
|
||||
**Avant** : Fichiers `.env` distincts dans chaque service
|
||||
**Après** : `shared.env` appliquée aux deux services via docker-compose.yml
|
||||
|
||||
## 🔧 Fichiers Modifiés
|
||||
|
||||
### Application Web
|
||||
|
||||
#### `docker-compose.yml`
|
||||
**Avant** :
|
||||
```yaml
|
||||
environment:
|
||||
SERVER_DIR: /home/innotex/NationsGloryRED/NationsGlory_ServeurBuild_Red
|
||||
volumes:
|
||||
- /home/innotex/NationsGloryRED/NationsGlory_ServeurBuild_Red:/mc-server
|
||||
```
|
||||
|
||||
**Après** :
|
||||
```yaml
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
SERVER_DIR: /mc-server
|
||||
RCON_HOST: ${RCON_HOST:-localhost}
|
||||
# ... autres variables
|
||||
volumes:
|
||||
- ${MC_SERVER_PATH:-../NationsGlory_ServeurBuild_Red}:/mc-server:ro
|
||||
network_mode: host # Pour accès depuis l'extérieur
|
||||
- ../shared.env # Configuration commune (priorité basse)
|
||||
- .env # Surcharges locales (priorité haute)
|
||||
```
|
||||
|
||||
#### `backend/src/server.js`
|
||||
**Modification** : CORS dynamique pour supporter toutes les origines
|
||||
```javascript
|
||||
// Avant
|
||||
app.use(cors({ origin: true, credentials: true }));
|
||||
### 2. Chemins Relatifs
|
||||
|
||||
// Après
|
||||
app.use(cors({
|
||||
origin: (origin, callback) => {
|
||||
const allowedOrigin = process.env.CORS_ORIGIN || true;
|
||||
callback(null, allowedOrigin);
|
||||
},
|
||||
credentials: true
|
||||
}));
|
||||
**Avant** : `/home/innotex/NationsGloryRED/NationsGlory_ServeurBuild_Red`
|
||||
**Après** : `${MC_SERVER_PATH:-../NationsGlory_ServeurBuild_Red}`
|
||||
|
||||
### 3. Détection Automatique API
|
||||
|
||||
**Avant** : API URL codée en dur (localhost seulement)
|
||||
**Après** : Détection via `window.location.protocol` + `window.location.hostname`
|
||||
|
||||
```javascript
|
||||
const API_URL = `${window.location.protocol}//${window.location.hostname}:4001/api`;
|
||||
```
|
||||
|
||||
#### `frontend/public/js/app.js`
|
||||
**Avant** :
|
||||
```javascript
|
||||
const API_URL = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
||||
? 'http://localhost:4001/api'
|
||||
: `http://${window.location.hostname}:4001/api`;
|
||||
### 4. CORS Dynamique
|
||||
|
||||
**Avant** : Accepter tous origins (security flaw)
|
||||
**Après** : CORS configurable par variable d'environnement
|
||||
|
||||
### 5. npm Install Fix
|
||||
|
||||
**Avant** : `RUN npm install --production` (oubliait devDependencies)
|
||||
**Après** : `RUN npm install` + vérification express
|
||||
|
||||
## 📋 Fichiers de Configuration
|
||||
|
||||
```
|
||||
shared.env.example # Template centralisé
|
||||
shared.env # Configuration réelle (non versionné)
|
||||
NationsGlory_ServeurBuild_Red/.env
|
||||
WebNationsGlory_ServeurBuild_Red/.env
|
||||
```
|
||||
|
||||
**Après** :
|
||||
```javascript
|
||||
const API_URL = (() => {
|
||||
const protocol = window.location.protocol; // http: ou https:
|
||||
const hostname = window.location.hostname; // IP ou domaine
|
||||
## 🔄 Scripts d'Automatisation
|
||||
|
||||
- `deploy.sh` - Déploiement complet
|
||||
- `stop.sh` - Arrêt des services
|
||||
- `check-config.sh` - Vérification + Git sync
|
||||
const port = '4001';
|
||||
|
||||
if (window.location.port === port) {
|
||||
|
||||
Reference in New Issue
Block a user