SPB Git

Repository Public MIT

route.ts 1.0 KB 20 lines typescript

1import { env } from "@/lib/env";2import { safeEqual } from "@/server/crypto";3import { healthDetails } from "@/server/ops";45export const dynamic = "force-dynamic";67const HEADERS = { "Cache-Control": "no-store", "X-Robots-Tag": "noindex" };89/**10 * Detailed health for monitoring: database, content source, free space, worker heartbeat, ffmpeg.11 * Requires `Authorization: Bearer $ATLAS_HEALTH_TOKEN`; without a configured token the endpoint does not exist.12 * 200 when everything is fine, 503 otherwise — so a plain HTTP check is enough.13 */14export async function GET(request: Request) {15  const token = env.healthToken, given = /^Bearer (.+)$/.exec(request.headers.get("authorization") ?? "")?.[1] ?? "";16  if (token.length < 16 || !safeEqual(given, token)) return new Response("Introuvable", { status: 404, headers: { ...HEADERS, "Content-Type": "text/plain; charset=utf-8" } });17  const details = await healthDetails();18  return Response.json(details, { status: details.status === "ok" ? 200 : 503, headers: HEADERS });19}20
Files main
Menu

Theme