Mise à jour de index.js

This commit is contained in:
soufiane 2025-11-03 22:10:57 +01:00
parent 39f7256c0b
commit a19dbfdd4b
2 changed files with 10 additions and 12 deletions

12
Jenkinsfile vendored
View File

@ -69,7 +69,7 @@ pipeline {
agent {
docker {
image 'node:18-alpine'
args '-u root' // permet laccè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
}

View File

@ -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 daccueil (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}`);
});