diff --git a/index.ts b/index.ts index 3b91b15..6c96148 100644 --- a/index.ts +++ b/index.ts @@ -31,7 +31,7 @@ Bun.serve<{key: string}>({ if ( req.method == "GET" ) { const { pathname } = new URL(req.url); if ( pathname === "/") return new Response(banner()) - if ( pathname === "/health") return toJSON(await checkHealth(true)); + if ( pathname === "/health") return await checkHealth(); if ( pathname === "/metrics") return new Response(await prometheus.registry.metrics()); if ( pathname === "/moduleHash") return toJSON(sqlite.selectAll(db, "moduleHash")); if ( pathname === "/traceId") return toJSON(sqlite.selectAll(db, "traceId")); diff --git a/src/health.ts b/src/health.ts index ea2eaee..a2fad6d 100644 --- a/src/health.ts +++ b/src/health.ts @@ -1,7 +1,9 @@ -export async function checkHealth(internalData: boolean) { - if (internalData == true){ - return {data: "OK", status: { status: 200 }}; - } - return {data: "Error: No connected webhooks", status: { status: 400 }}; +import { toText } from "./http.js"; +import { getSingleMetric } from "./prometheus.js"; +export async function checkHealth() { + if (await getSingleMetric("trace_id") > 0 ) { + return new Response("OK"); + } + return toText("Error: No connected webhooks", 400); }; \ No newline at end of file