From d0683b363f44cce2349b770b6da7ab8dfe275032 Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Fri, 21 Nov 2025 15:28:30 +0000 Subject: [PATCH] Update startup script to load environment variables correctly Modify `deployment/check_frontend.sh` to source the `.env` file before starting the Node.js development server. This ensures that environment variables, such as `DATABASE_URL`, are properly loaded, resolving startup errors on non-Replit environments. Also updates `replit.md` to document this fix. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 21e2b3ab-3e67-45ff-819b-a2db15c27292 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/dI1I79r --- .replit | 4 ++++ deployment/check_frontend.sh | 5 +++++ replit.md | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/.replit b/.replit index 30bea15..3e67b19 100644 --- a/.replit +++ b/.replit @@ -14,6 +14,10 @@ run = ["npm", "run", "start"] localPort = 5000 externalPort = 80 +[[ports]] +localPort = 34661 +externalPort = 3001 + [[ports]] localPort = 41303 externalPort = 3002 diff --git a/deployment/check_frontend.sh b/deployment/check_frontend.sh index b89fb79..8644a48 100644 --- a/deployment/check_frontend.sh +++ b/deployment/check_frontend.sh @@ -25,6 +25,11 @@ else # Wait a moment sleep 2 + # Load environment variables from .env file + set -a + source "$WORK_DIR/.env" 2>/dev/null || true + set +a + # Start frontend cd "$WORK_DIR" nohup npm run dev >> "$LOG_FILE" 2>&1 & diff --git a/replit.md b/replit.md index ea6ad98..ad1a87d 100644 --- a/replit.md +++ b/replit.md @@ -43,6 +43,19 @@ Sistema di rilevamento intrusioni per router MikroTik basato su Machine Learning ## Fix Recenti (Novembre 2025) +### ✅ Frontend Environment Variables Fix (21 Nov 2025 - 16:30) +- **Problema**: Frontend Node.js non si avviava su server AlmaLinux con errore `DATABASE_URL must be set` +- **Causa**: Script `check_frontend.sh` non caricava variabili d'ambiente dal file `.env` +- **Soluzione**: + - Modificato `deployment/check_frontend.sh` per caricare `.env` prima di eseguire `npm run dev` + - Usato `set -a; source .env; set +a` per esportare tutte le variabili +- **Risultato**: Frontend si avvia correttamente leggendo `DATABASE_URL` e altre variabili da `.env` + +### ✅ Form Validation Migliorata (21 Nov 2025 - 15:00) +- **API ML Endpoints**: Timeout configurabili (120s train/detect, 10s stats), validazione input, messaggi errore specifici (504 timeout, 503 backend down, 400 validation) +- **Whitelist Form**: Convertito a react-hook-form + zodResolver, validazione IP completa (regex + controllo ottetti 0-255) +- **Training Forms**: Due form separati (trainForm/detectForm), schema Zod con z.coerce.number(), FormDescription per suggerimenti + ### ✅ Sistema Completamente Funzionante (17 Nov 2025 - 19:30) - **Backend Python FastAPI**: ✅ Porta 8000, modello ML caricato, endpoint /stats funzionante - **Database PostgreSQL**: ✅ 5 tabelle (network_logs, detections, routers, whitelist, training_history)