the-tip-top-backend/index.js
wkadmin 40b471e76e
All checks were successful
the-tip-top-backend/pipeline/head This commit looks good
Actualiser index.js
2025-10-21 18:07:16 +00:00

44 lines
1.1 KiB
JavaScript

import express from 'express';
import client from 'prom-client';
import dotenv from 'dotenv';
dotenv.config();
const app = express();
const PORT = process.env.PORT || 4000;
// --- Prometheus setup ---
const collectDefaultMetrics = client.collectDefaultMetrics;
collectDefaultMetrics(); // CPU, mémoire, etc.
const httpRequestCounter = new client.Counter({
name: 'http_requests_total',
help: 'Nombre total de requêtes HTTP reçues',
labelNames: ['method', 'route', 'status'],
});
app.use((req, res, next) => {
res.on('finish', () => {
httpRequestCounter.inc({
method: req.method,
route: req.route?.path || req.path,
status: res.statusCode,
});
});
next();
});
// --- Ton API existante ---
app.get('/api', (req, res) => {
res.json({ message: 'API The Tip Top 🚀' });
});
// --- Endpoint de métriques ---
app.get('/metrics', async (req, res) => {
res.set('Content-Type', client.register.contentType);
res.end(await client.register.metrics());
});
app.listen(PORT, () => {
console.log(`🚀 Backend The Tip Top lancé sur le port ${PORT}`);
});