# 📝 Modifications Techniques RĂ©sumĂ© des changements pour portabilitĂ© et simplification. ## ✅ Objectifs Atteints - ✅ Chemins relatifs (100% portable) - ✅ Configuration centralisĂ©e (shared.env) - ✅ DĂ©tection automatique API - ✅ Synchronisation Git automatique - ✅ DĂ©ploiement unifiĂ© ## 🔑 Changements ClĂ©s ### 1. Configuration CentralisĂ©e **Avant** : Fichiers `.env` distincts dans chaque service **AprĂšs** : `shared.env` appliquĂ©e aux deux services via docker-compose.yml ```yaml env_file: - ../shared.env # Configuration commune (prioritĂ© basse) - .env # Surcharges locales (prioritĂ© haute) ``` ### 2. Chemins Relatifs **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`; ``` ### 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 ``` ## 🔄 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) { return `${protocol}//${hostname}:${port}/api`; } return `${protocol}//${hostname}:${port}/api`; })(); ``` ✅ **Supporte automatiquement** : `http:` et `https:`, localhost, IP, domaine ### Serveur Minecraft #### `docker-compose.yml` Ajout du support des variables d'environnement : ```yaml env_file: - .env environment: SERVER_PORT: ${SERVER_PORT:-25565} RCON_PORT: ${RCON_PORT:-25575} RCON_PASSWORD: ${RCON_PASSWORD:-minecraft} # ... etc ``` #### `.env.example` ComplĂ©tĂ© avec toutes les variables nĂ©cessaires ## 🔐 Configuration Requise ### Fichier `.env` du serveur Minecraft ```bash cp NationsGlory_ServeurBuild_Red/.env.example NationsGlory_ServeurBuild_Red/.env nano NationsGlory_ServeurBuild_Red/.env ``` **ParamĂštres importants** : - `RCON_PASSWORD` : Changez pour la production ### Fichier `.env` de l'application web ```bash cp WebNationsGlory_ServeurBuild_Red/.env.example WebNationsGlory_ServeurBuild_Red/.env nano WebNationsGlory_ServeurBuild_Red/.env ``` **ParamĂštres critiques** : - `SESSION_SECRET` : GĂ©nĂ©rez avec `openssl rand -base64 32` - `RCON_PASSWORD` : **Doit ĂȘtre identique** au serveur MC - `MC_SERVER_PATH` : Chemin relatif vers le serveur (dĂ©faut: `../NationsGlory_ServeurBuild_Red`) ## 🚀 Utilisation ### 1. VĂ©rification de la configuration ```bash ./check-config.sh ``` ### 2. DĂ©ploiement ```bash ./deploy.sh ``` ### 3. AccĂšs - **Serveur Minecraft** : `votre-ip:25565` - **Interface Web** : `http://votre-ip:4001` ### 4. ArrĂȘt ```bash ./stop.sh ``` ## 🌐 AccĂšs Ă  Distance L'application web fonctionne maintenant nativement avec : - ✅ `http://localhost:4001` (local) - ✅ `http://192.168.1.X:4001` (rĂ©seau local) - ✅ `http://votre-ip-publique:4001` (internet) - ✅ `http://votre-domaine.com:4001` (domaine) - ✅ `https://votre-domaine.com` (avec nginx reverse proxy) **Aucune configuration supplĂ©mentaire nĂ©cessaire** dans le code. ## 📩 PortabilitĂ© ### DĂ©ployer sur une nouvelle machine 1. **Copier le dossier** `Serveur NationsGlory` complet 2. **CrĂ©er les fichiers `.env`** : ```bash cd WebNationsGlory_ServeurBuild_Red cp .env.example .env nano .env # Configurer SESSION_SECRET et RCON_PASSWORD cd ../NationsGlory_ServeurBuild_Red cp .env.example .env nano .env # Configurer RCON_PASSWORD (mĂȘme valeur) ``` 3. **DĂ©ployer** : ```bash cd .. ./deploy.sh ``` **C'est tout !** 🎉 ### Pas de dĂ©pendances aux chemins - ❌ Plus de `/home/innotex/...` - ❌ Plus de configuration IP hardcodĂ©e - ✅ Tout est relatif au dossier parent - ✅ DĂ©tection automatique de l'environnement ## 🔒 SĂ©curitĂ© ### Checklist de production - [ ] Changez `SESSION_SECRET` dans `.env` de l'app web - [ ] Changez `RCON_PASSWORD` dans les deux `.env` - [ ] Ouvrez les ports firewall (25565, 25575, 4001) - [ ] Configurez nginx avec SSL (optionnel mais recommandĂ©) - [ ] Restreignez l'accĂšs admin (firewall, VPN) - [ ] Configurez les sauvegardes automatiques ### Exemple de gĂ©nĂ©ration de secrets ```bash # SESSION_SECRET openssl rand -base64 32 # RCON_PASSWORD (alphanumĂ©rique) openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' ``` ## 📊 Architecture ``` Serveur NationsGlory/ ├── deploy.sh # DĂ©marrage unifiĂ© ├── stop.sh # ArrĂȘt unifiĂ© ├── check-config.sh # VĂ©rification │ ├── NationsGlory_ServeurBuild_Red/ │ ├── .env # Config du serveur MC │ ├── docker-compose.yml # Orchestration Docker │ └── mcpc.jar # Serveur Minecraft │ └── WebNationsGlory_ServeurBuild_Red/ ├── .env # Config de l'app web ├── docker-compose.yml # Orchestration Docker ├── backend/ # API Node.js └── frontend/ # Interface web Communication: - App Web → Serveur MC (RCON sur localhost:25575) - Client Web → App Web (HTTP sur port 4001) - Client MC → Serveur MC (TCP sur port 25565) ``` ## 🎓 Points Techniques ### 1. Montage relatif du serveur MC Le docker-compose de l'app web monte le serveur avec un chemin relatif : ```yaml volumes: - ${MC_SERVER_PATH:-../NationsGlory_ServeurBuild_Red}:/mc-server:ro ``` Le `:ro` (read-only) assure que l'app web ne modifie pas les fichiers du serveur. ### 2. Network mode host ```yaml network_mode: host ``` Permet Ă  l'application d'ĂȘtre accessible depuis l'extĂ©rieur sans NAT Docker. NĂ©cessaire pour que l'API fonctionne avec n'importe quelle IP/domaine. ### 3. DĂ©tection automatique du protocole Le frontend dĂ©tecte automatiquement `http:` ou `https:` depuis `window.location.protocol`, permettant le support SSL transparent via nginx. ### 4. Variables d'environnement avec valeurs par dĂ©faut ```yaml RCON_PORT: ${RCON_PORT:-25575} ``` Si `RCON_PORT` n'est pas dĂ©fini dans `.env`, utilise `25575`. ## 🐛 DĂ©pannage ### Le script deploy.sh Ă©choue ```bash ./check-config.sh # VĂ©rifier la configuration ``` ### L'app web ne se connecte pas au serveur MC 1. VĂ©rifiez que `RCON_PASSWORD` est identique 2. VĂ©rifiez que le serveur MC a dĂ©marrĂ© complĂštement 3. Testez RCON : `docker exec -it mc-nationsglory rcon-cli` ### L'API ne rĂ©pond pas depuis l'extĂ©rieur 1. VĂ©rifiez le pare-feu : `sudo ufw status` 2. Ouvrez le port : `sudo ufw allow 4001/tcp` 3. Testez : `curl http://votre-ip:4001/api/health` ## 📚 RĂ©fĂ©rences - [Docker Compose Documentation](https://docs.docker.com/compose/) - [Express.js CORS](https://expressjs.com/en/resources/middleware/cors.html) - [Nginx Reverse Proxy](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/) --- **Date de modification** : FĂ©vrier 2026 **Version** : 2.0 - Configuration portable