290 lines
7.4 KiB
Markdown
290 lines
7.4 KiB
Markdown
# 📝 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
|