47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
// GET /relay/health — public liveness check. No auth, no credit
|
|
// accounting. Returns a minimal status object so monitoring + Recap's
|
|
// /api/relay/status can verify the relay is reachable.
|
|
|
|
import express from "express";
|
|
import { readFileSync } from "fs";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
import { getConfigSnapshot } from "../config.js";
|
|
|
|
// Pull the version off server/package.json once at module load — the
|
|
// build pipeline bumps that file in lockstep with each StartOS version
|
|
// bump, so the health endpoint always reports a meaningful number.
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
let VERSION = "unknown";
|
|
try {
|
|
const pkg = JSON.parse(
|
|
readFileSync(path.join(__dirname, "..", "package.json"), "utf8")
|
|
);
|
|
VERSION = pkg.version || "unknown";
|
|
} catch {
|
|
// Read failure is non-fatal — health still works, just reports
|
|
// "unknown". Build pipeline shouldn't ever ship a missing
|
|
// package.json so this branch is defensive only.
|
|
}
|
|
|
|
export function healthRouter() {
|
|
const router = express.Router();
|
|
|
|
router.get("/health", async (_req, res) => {
|
|
const cfg = await getConfigSnapshot();
|
|
res.json({
|
|
ok: true,
|
|
service: "recap-relay",
|
|
version: VERSION,
|
|
backends: {
|
|
gemini: !!cfg.relay_gemini_api_key,
|
|
parakeet: !!cfg.relay_parakeet_base_url,
|
|
gemma: !!cfg.relay_gemma_base_url,
|
|
},
|
|
admin_enabled: !!cfg.relay_admin_password_hash,
|
|
});
|
|
});
|
|
|
|
return router;
|
|
}
|