# 📝 RĂ©sumĂ© des Modifications - Configuration Portable Ce document rĂ©sume les modifications apportĂ©es pour rendre le dĂ©ploiement portable et simplifiĂ©. ## 🎯 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 ## 📁 Fichiers Créé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 ### Application Web (`WebNationsGlory_ServeurBuild_Red/`) - **`.env.example`** : Template de configuration avec toutes les variables - **`nginx.conf.example`** : Configuration nginx pour production avec SSL ## 🔧 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 ``` #### `backend/src/server.js` **Modification** : CORS dynamique pour supporter toutes les origines ```javascript // Avant app.use(cors({ origin: true, credentials: true })); // AprĂšs app.use(cors({ origin: (origin, callback) => { const allowedOrigin = process.env.CORS_ORIGIN || true; callback(null, allowedOrigin); }, credentials: true })); ``` #### `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`; ``` **AprĂšs** : ```javascript const API_URL = (() => { const protocol = window.location.protocol; // http: ou https: const hostname = window.location.hostname; // IP ou domaine 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