Phase 1: lock cron, reload chaud, argon2, providers, IMDb lookup, cache LRU, /health, /metrics, rate limit, UI dark, biome
This commit is contained in:
35
routes/health.js
Normal file
35
routes/health.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// /health (JSON liveness/readiness) and /metrics (Prometheus exposition).
|
||||
|
||||
import { getRatings } from '../lib/imdbRatings.js';
|
||||
import { imdbRatingsCount, registry } from '../lib/metrics.js';
|
||||
|
||||
export default async function healthRoutes(fastify) {
|
||||
fastify.get('/health', async (_req, reply) => {
|
||||
reply.header('Cache-Control', 'no-store');
|
||||
let ratings = 0;
|
||||
let ratingsOk = false;
|
||||
try {
|
||||
const map = await getRatings();
|
||||
ratings = map.size;
|
||||
imdbRatingsCount.set(ratings);
|
||||
ratingsOk = true;
|
||||
} catch {
|
||||
/* ignore — reported via ratingsOk */
|
||||
}
|
||||
const status = ratingsOk ? 'ok' : 'degraded';
|
||||
reply.code(ratingsOk ? 200 : 503);
|
||||
return {
|
||||
status,
|
||||
uptime: Math.round(process.uptime()),
|
||||
pid: process.pid,
|
||||
node: process.version,
|
||||
memory_mb: Math.round(process.memoryUsage().rss / 1024 / 1024),
|
||||
imdb_ratings: ratings,
|
||||
};
|
||||
});
|
||||
|
||||
fastify.get('/metrics', async (_req, reply) => {
|
||||
reply.header('Content-Type', registry.contentType);
|
||||
return registry.metrics();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user