Mise à jour de index.js
This commit is contained in:
parent
d06a461973
commit
c3c3d45d6f
26
index.js
26
index.js
|
|
@ -9,7 +9,6 @@ import { pool } from "./db.js";
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// --- Middlewares globaux ---
|
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
origin: ["http://localhost:3000", "https://dsp5-archi-o24a-15m-g3.fr"],
|
origin: ["http://localhost:3000", "https://dsp5-archi-o24a-15m-g3.fr"],
|
||||||
|
|
@ -20,7 +19,17 @@ app.use(helmet());
|
||||||
app.use(morgan("tiny"));
|
app.use(morgan("tiny"));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
// --- Vérification connexion DB ---
|
// ✅ Nouvelle route /health pour Jenkins
|
||||||
|
app.get("/health", (req, res) => {
|
||||||
|
res.status(200).json({ status: "ok" });
|
||||||
|
});
|
||||||
|
|
||||||
|
// ✅ Route racine (pour éviter le 404 sur /)
|
||||||
|
app.get("/", (req, res) => {
|
||||||
|
res.json({ message: "✅ API The Tip Top en ligne !" });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Vérif base de données
|
||||||
app.get("/db-check", async (req, res) => {
|
app.get("/db-check", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const result = await pool.query("SELECT NOW()");
|
const result = await pool.query("SELECT NOW()");
|
||||||
|
|
@ -30,16 +39,7 @@ app.get("/db-check", async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/health", (req, res) => {
|
// Prometheus
|
||||||
res.status(200).json({ status: "ok" });
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- Route d’accueil ---
|
|
||||||
app.get("/", (req, res) => {
|
|
||||||
res.json({ message: "✅ API Thé Tip Top en ligne et opérationnelle g1001001 !" });
|
|
||||||
});
|
|
||||||
|
|
||||||
// --- Monitoring Prometheus ---
|
|
||||||
const collectDefaultMetrics = client.collectDefaultMetrics;
|
const collectDefaultMetrics = client.collectDefaultMetrics;
|
||||||
collectDefaultMetrics();
|
collectDefaultMetrics();
|
||||||
app.get("/metrics", async (req, res) => {
|
app.get("/metrics", async (req, res) => {
|
||||||
|
|
@ -47,7 +47,7 @@ app.get("/metrics", async (req, res) => {
|
||||||
res.end(await client.register.metrics());
|
res.end(await client.register.metrics());
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Lancement du serveur ---
|
// Lancement serveur
|
||||||
const PORT = process.env.PORT || 4000;
|
const PORT = process.env.PORT || 4000;
|
||||||
app.listen(PORT, "0.0.0.0", () => {
|
app.listen(PORT, "0.0.0.0", () => {
|
||||||
console.log(`🚀 Backend lancé sur 0.0.0.0:${PORT} ✅`);
|
console.log(`🚀 Backend lancé sur 0.0.0.0:${PORT} ✅`);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user