Merge pull request #113 from trails-cool/health-version

Add deployed version to health endpoints
This commit is contained in:
Ullrich Schäfer 2026-03-27 20:48:31 +01:00 committed by GitHub
commit b4412d1b9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 7 deletions

View file

@ -1,13 +1,13 @@
import { data } from "react-router";
import { withDb } from "@trails-cool/db";
const version = process.env.SENTRY_RELEASE ?? "dev";
export async function loader() {
try {
await withDb(async () => {
// withDb creates a connection — if it succeeds, DB is reachable
});
return data({ status: "ok", db: "connected" });
await withDb(async () => {});
return data({ status: "ok", version, db: "connected" });
} catch {
return data({ status: "degraded", db: "unreachable" }, { status: 503 });
return data({ status: "degraded", version, db: "unreachable" }, { status: 503 });
}
}

View file

@ -71,16 +71,18 @@ async function handleMetrics(_req: IncomingMessage, res: ServerResponse): Promis
res.end(metrics);
}
const version = process.env.SENTRY_RELEASE ?? "dev";
async function handleHealth(_req: IncomingMessage, res: ServerResponse): Promise<void> {
try {
const { withDb, db } = await import("@trails-cool/db");
const { sql } = await import("drizzle-orm");
await withDb(async () => { await db.execute(sql`SELECT 1`); });
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ status: "ok", db: "connected" }));
res.end(JSON.stringify({ status: "ok", version, db: "connected" }));
} catch {
res.writeHead(503, { "Content-Type": "application/json" });
res.end(JSON.stringify({ status: "degraded", db: "unreachable" }));
res.end(JSON.stringify({ status: "degraded", version, db: "unreachable" }));
}
}