From a19dbfdd4b46e6196e1f311d573b565064228566 Mon Sep 17 00:00:00 2001 From: soufiane Date: Mon, 3 Nov 2025 22:10:57 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20index.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 12 ++++-------- index.js | 10 ++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2352952b..1a213644 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -69,7 +69,7 @@ pipeline { agent { docker { image 'node:18-alpine' - args '-u root' // permet l’accès root pour npm si besoin + args '-u root' } } steps { @@ -136,10 +136,8 @@ pipeline { sh """ echo "📂 DEPLOY_PATH utilisé : ${DEPLOY_PATH}" - # Vérifie la présence du fichier docker-compose.yml if [ ! -f "${DEPLOY_PATH}/docker-compose.yml" ]; then echo "❌ Fichier docker-compose.yml introuvable dans ${DEPLOY_PATH}" - echo "📁 Contenu du dossier :" ls -l ${DEPLOY_PATH} || echo "⚠️ Impossible de lister le contenu." exit 1 fi @@ -151,14 +149,12 @@ pipeline { echo "🔄 Recréation du conteneur backend..." docker compose up -d --force-recreate backend - - echo "✅ Déploiement terminé avec succès sur ${DEPLOY_PATH}" """ } } /* ─────────────────────────────── - * 8️⃣ Vérification de santé + * 8️⃣ Vérification de santé (via /health) * ─────────────────────────────── */ stage('Health Check') { steps { @@ -170,8 +166,8 @@ pipeline { def statusCode = "000" for (int i = 1; i <= 10; i++) { - statusCode = sh(script: "curl -k -s -o /dev/null -w '%{http_code}' https://${domain}/ || echo 000", returnStdout: true).trim() - if (statusCode in ['200', '301', '302']) { + statusCode = sh(script: "curl -k -s -o /dev/null -w '%{http_code}' https://${domain}/health || echo 000", returnStdout: true).trim() + if (statusCode in ['200']) { echo "✅ Backend ${env.ENV} opérationnel (HTTP ${statusCode})" return } diff --git a/index.js b/index.js index 7d6c448e..b7d95247 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,6 @@ import morgan from "morgan"; import client from "prom-client"; import { pool } from "./db.js"; - dotenv.config(); const app = express(); @@ -21,6 +20,10 @@ app.use(helmet()); app.use(morgan("tiny")); app.use(express.json()); +// --- Endpoint de santé pour CI/CD et monitoring --- +app.get("/health", (req, res) => { + res.status(200).json({ status: "ok" }); +}); // --- Vérification connexion DB --- app.get("/db-check", async (req, res) => { @@ -32,7 +35,6 @@ app.get("/db-check", async (req, res) => { } }); - // --- Route d’accueil (fix pour 'Cannot GET /') --- app.get("/", (req, res) => { res.json({ message: "✅ API Thé Tip Top en ligne et opérationnelle vk1001001 !" }); @@ -48,6 +50,6 @@ app.get("/metrics", async (req, res) => { // --- Lancement du serveur --- const PORT = process.env.PORT || 4000; -app.listen(4000, "0.0.0.0", () => { - console.log("🚀 Backend lancé sur 0.0.0.0:4000 ✅"); +app.listen(PORT, "0.0.0.0", () => { + console.log(`🚀 Backend lancé sur 0.0.0.0:${PORT} ✅`); });