Configuration portable : chemins relatifs et API dynamique
This commit is contained in:
36
.env.example
Normal file
36
.env.example
Normal file
@@ -0,0 +1,36 @@
|
||||
# ====================================
|
||||
# Configuration Application Web Admin
|
||||
# ====================================
|
||||
|
||||
# Environnement
|
||||
NODE_ENV=production
|
||||
|
||||
# Port de l'application web
|
||||
PORT=4001
|
||||
|
||||
# Chemin vers le serveur Minecraft (RELATIF au dossier parent)
|
||||
# Par défaut: ../NationsGlory_ServeurBuild_Red
|
||||
# Cela permet de pointer vers le serveur MC sans chemins absolus
|
||||
MC_SERVER_PATH=../NationsGlory_ServeurBuild_Red
|
||||
|
||||
# Configuration RCON du serveur Minecraft
|
||||
# Utiliser 'localhost' si l'app web et le serveur MC sont sur la même machine
|
||||
# Sinon, utiliser l'IP du serveur MC
|
||||
RCON_HOST=localhost
|
||||
RCON_PORT=25575
|
||||
RCON_PASSWORD=minecraft
|
||||
|
||||
# Secret de session (CHANGEZ CETTE VALEUR EN PRODUCTION!)
|
||||
# Générez avec: openssl rand -base64 32
|
||||
SESSION_SECRET=changez-moi-en-production-utilisez-une-valeur-aleatoire-securisee
|
||||
|
||||
# Domaine/IP publique (optionnel)
|
||||
# Utilisé pour générer des URLs complètes si nécessaire
|
||||
# Laissez vide pour détection automatique
|
||||
# PUBLIC_HOST=votre-domaine.com
|
||||
# PUBLIC_HOST=192.168.1.100
|
||||
|
||||
# Configuration CORS (optionnel)
|
||||
# Laissez vide pour autoriser toutes les origines (développement)
|
||||
# En production, spécifiez votre domaine
|
||||
# CORS_ORIGIN=https://votre-domaine.com
|
||||
@@ -5,8 +5,8 @@ WORKDIR /app
|
||||
# Copy package files
|
||||
COPY backend/package*.json ./
|
||||
|
||||
# Copy pre-built node_modules (already present)
|
||||
COPY backend/node_modules ./node_modules/
|
||||
# Install dependencies
|
||||
RUN npm install --production
|
||||
|
||||
# Copy application code
|
||||
COPY backend/src ./src
|
||||
|
||||
@@ -28,8 +28,15 @@ const frontendPath = (() => {
|
||||
// Middlewares
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// CORS dynamique pour supporter n'importe quelle origine
|
||||
app.use(cors({
|
||||
origin: true,
|
||||
origin: (origin, callback) => {
|
||||
// Autoriser toutes les origines en mode production
|
||||
// ou l'origine spécifiée dans les variables d'environnement
|
||||
const allowedOrigin = process.env.CORS_ORIGIN || true;
|
||||
callback(null, allowedOrigin);
|
||||
},
|
||||
credentials: true
|
||||
}));
|
||||
|
||||
|
||||
@@ -6,21 +6,26 @@ services:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: webnationsglory-admin
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
PORT: 4001
|
||||
SERVER_DIR: /home/innotex/NationsGloryRED/NationsGlory_ServeurBuild_Red
|
||||
RCON_HOST: localhost
|
||||
RCON_PORT: 25575
|
||||
SESSION_SECRET: your-secret-key-change-in-production
|
||||
NODE_ENV: ${NODE_ENV:-production}
|
||||
PORT: ${PORT:-4001}
|
||||
SERVER_DIR: /mc-server
|
||||
RCON_HOST: ${RCON_HOST:-localhost}
|
||||
RCON_PORT: ${RCON_PORT:-25575}
|
||||
RCON_PASSWORD: ${RCON_PASSWORD:-minecraft}
|
||||
SESSION_SECRET: ${SESSION_SECRET:-your-secret-key-change-in-production}
|
||||
volumes:
|
||||
- /home/innotex/NationsGloryRED/NationsGlory_ServeurBuild_Red:/mc-server
|
||||
# Montage relatif du serveur MC (depuis le dossier parent)
|
||||
- ${MC_SERVER_PATH:-../NationsGlory_ServeurBuild_Red}:/mc-server:ro
|
||||
- web-admin-data:/app/data
|
||||
ports:
|
||||
- "4001:4001"
|
||||
- "${PORT:-4001}:${PORT:-4001}"
|
||||
network_mode: host
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:4001/api/health"]
|
||||
test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:${PORT:-4001}/api/health || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
@@ -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;
|
||||
|
||||
118
nginx.conf.example
Normal file
118
nginx.conf.example
Normal file
@@ -0,0 +1,118 @@
|
||||
# ====================================
|
||||
# Configuration Nginx - NationsGlory Web Admin
|
||||
# ====================================
|
||||
#
|
||||
# Ce fichier fournit une configuration exemple pour utiliser nginx
|
||||
# comme reverse proxy devant l'application web admin.
|
||||
#
|
||||
# Avantages :
|
||||
# - Support HTTPS/SSL
|
||||
# - Cache des assets statiques
|
||||
# - Compression gzip
|
||||
# - Sécurité renforcée
|
||||
#
|
||||
# Installation :
|
||||
# 1. Copiez ce fichier dans /etc/nginx/sites-available/nationsglory
|
||||
# 2. Modifiez les domaines et chemins SSL
|
||||
# 3. Créez le lien symbolique : ln -s /etc/nginx/sites-available/nationsglory /etc/nginx/sites-enabled/
|
||||
# 4. Testez : nginx -t
|
||||
# 5. Rechargez : systemctl reload nginx
|
||||
|
||||
# Redirection HTTP vers HTTPS
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name votre-domaine.com www.votre-domaine.com;
|
||||
|
||||
# Redirection vers HTTPS
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
# Configuration HTTPS
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name votre-domaine.com www.votre-domaine.com;
|
||||
|
||||
# Certificats SSL (Let's Encrypt ou autre)
|
||||
ssl_certificate /etc/letsencrypt/live/votre-domaine.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/votre-domaine.com/privkey.pem;
|
||||
|
||||
# Configuration SSL moderne et sécurisée
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
|
||||
ssl_prefer_server_ciphers off;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
# HSTS (optionnel mais recommandé)
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# Sécurité supplémentaire
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
|
||||
# Logs
|
||||
access_log /var/log/nginx/nationsglory-access.log;
|
||||
error_log /var/log/nginx/nationsglory-error.log;
|
||||
|
||||
# Taille maximale des uploads (pour les backups)
|
||||
client_max_body_size 500M;
|
||||
|
||||
# Proxy vers l'application Node.js
|
||||
location / {
|
||||
proxy_pass http://localhost:4001;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
# Headers pour le proxy
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $host;
|
||||
proxy_set_header X-Forwarded-Port $server_port;
|
||||
|
||||
# Support WebSocket (si nécessaire dans le futur)
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
# Timeouts
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 60s;
|
||||
}
|
||||
|
||||
# Cache des assets statiques
|
||||
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
|
||||
proxy_pass http://localhost:4001;
|
||||
proxy_cache_valid 200 7d;
|
||||
expires 7d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Compression gzip
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
|
||||
}
|
||||
|
||||
# Configuration alternative : Accès par sous-domaine
|
||||
# Décommentez si vous voulez utiliser admin.votre-domaine.com
|
||||
#
|
||||
# server {
|
||||
# listen 443 ssl http2;
|
||||
# listen [::]:443 ssl http2;
|
||||
# server_name admin.votre-domaine.com;
|
||||
#
|
||||
# ssl_certificate /etc/letsencrypt/live/votre-domaine.com/fullchain.pem;
|
||||
# ssl_certificate_key /etc/letsencrypt/live/votre-domaine.com/privkey.pem;
|
||||
#
|
||||
# # Même configuration que ci-dessus
|
||||
# location / {
|
||||
# proxy_pass http://localhost:4001;
|
||||
# # ... (même configuration proxy)
|
||||
# }
|
||||
# }
|
||||
Reference in New Issue
Block a user