Add version (git SHA) to health endpoints
Returns SENTRY_RELEASE (set at build time) as the version field, making it easy to verify which commit is deployed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
98df1501c7
commit
0ff9052ae8
2 changed files with 9 additions and 7 deletions
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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" }));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue