frieren

~ / frieren

a self-hosted git server in one binary — everyone reads, only the owner writes

frieren / web / app / api / health / route.ts 901 B · raw

import { apiBase } from "@/lib/api";

// Reports whether this deployment can reach its backend — the first place to
// look when the site shows the offline card.
export const dynamic = "force-dynamic";

export async function GET() {
  const base = apiBase();
  if (!base) {
    return Response.json({ configured: false, ok: false });
  }
  const started = Date.now();
  try {
    const res = await fetch(`${base}/api/repos`, { cache: "no-store" });
    return Response.json({
      configured: true,
      ok: res.ok,
      status: res.status,
      ms: Date.now() - started,
    });
  } catch (e) {
    const cause = e instanceof Error ? (e.cause as { code?: string } | undefined) : undefined;
    return Response.json({
      configured: true,
      ok: false,
      error: e instanceof Error ? e.message : String(e),
      code: cause?.code ?? null,
      ms: Date.now() - started,
    });
  }
}