import { statusDictionary } from "./utils"; export type Status = | "operational" | "degraded_performance" | "partial_outage" | "major_outage" | "under_maintenance" | "unknown" | "incident"; export type StatusResponse = { status: Status }; export async function getStatus( slug: string, baseUrl = process.env.OPENSTATUS_API_URL ?? "https://api.openstatus.dev", ): Promise { // read at runtime on the server: no NEXT_PUBLIC_ prefix, so deployments // shipping prebuilt images can still point badges at their own API const base = baseUrl.replace(/\/+$/, "") || "https://api.openstatus.dev"; try { const res = await fetch(`${base}/public/status/${slug}`, { cache: "no-cache", }); if (res.ok) { const data = (await res.json()) as StatusResponse; return data; } } catch { // network-level failures (unreachable host, DNS, …) degrade to "unknown" // instead of bubbling a 500 out of the badge routes } return { status: "unknown" }; } export type StatusWidgetProps = { slug: string; href?: string; }; export async function StatusWidget({ slug, href }: StatusWidgetProps) { const { status } = await getStatus(slug); const { label, color } = statusDictionary[status]; return ( {label} {status === "operational" ? ( ) : null} ); }