Files
EpicNext-Cms/src/app/api/health/route.ts
T
openhands df38dccbf1
Local Build and Deploy / deploy (push) Failing after 46s
style: format code biome
2026-07-13 21:57:41 +02:00

48 lines
1.2 KiB
TypeScript

import { env } from "@/env";
import { apiJson } from "@/lib/api";
import { prisma } from "@/lib/prisma";
import { rcon } from "@/lib/services/rcon";
export const dynamic = "force-dynamic";
/**
* Ops health probe: database reachability, emulator RCON reachability, SMTP
* (when configured), and runtime info. Returns HTTP 200 always (read the
* `status`/`database` fields), so it's safe for uptime monitors that only care
* about reachability.
*/
export async function GET() {
const database = await prisma.$queryRaw`SELECT 1`
.then(() => true)
.catch(() => false);
const emulator = await rcon.send("ping", null).catch(() => false);
let smtp = null;
if (env.SMTP_HOST) {
const nodemailer = await import("nodemailer");
const test = nodemailer.createTransport({
host: env.SMTP_HOST,
port: env.SMTP_PORT,
secure: env.SMTP_SECURE,
auth: env.SMTP_USER
? { user: env.SMTP_USER, pass: env.SMTP_PASSWORD ?? "" }
: undefined,
});
smtp = await test
.verify()
.then(() => true)
.catch(() => false);
}
return apiJson({
status: database ? "ok" : "degraded",
database,
emulator,
smtp,
node: process.version,
uptime: Math.round(process.uptime()),
time: new Date().toISOString(),
});
}