Skip to content

Open-source status page, incident response and uptime monitoring

chore: lazy monday improvements (#1533)

Maximilian Kaskee75719a88319
diff --git a/apps/dashboard/src/components/data-table/status-pages/columns.tsx b/apps/dashboard/src/components/data-table/status-pages/columns.tsx
index 47cd03d17..e86b64b86 100644
--- a/apps/dashboard/src/components/data-table/status-pages/columns.tsx
+++ b/apps/dashboard/src/components/data-table/status-pages/columns.tsx
@@ -65,6 +65,7 @@ export const columns: ColumnDef<StatusPage>[] = [
},
{
accessorKey: "domain",
+ accessorFn: (row) => row.customDomain,
header: "Domain",
cell: ({ row }) => {
const value = row.getValue("domain");
diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/badge/route.tsx b/apps/status-page/src/app/(status-page)/[domain]/(public)/badge/route.tsx
new file mode 100644
index 000000000..78254e92c
--- /dev/null
+++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/badge/route.tsx
@@ -0,0 +1,74 @@
+import { ImageResponse } from "next/og";
+import type { NextRequest } from "next/server";
+
+import type { Status } from "@openstatus/react";
+import { getStatus } from "@openstatus/react";
+
+// Keep the `label` size within a maximum of 'Operational' to stay within the `SIZE` restriction
+const statusDictionary: Record<Status, { label: string; color: string }> = {
+ operational: {
+ label: "Operational",
+ color: "bg-green-500",
+ },
+ degraded_performance: {
+ label: "Degraded",
+ color: "bg-yellow-500",
+ },
+ partial_outage: {
+ label: "Outage",
+ color: "bg-yellow-500",
+ },
+ major_outage: {
+ label: "Outage",
+ color: "bg-red-500",
+ },
+ unknown: {
+ label: "Unknown",
+ color: "bg-gray-500",
+ },
+ incident: {
+ label: "Incident",
+ color: "bg-yellow-500",
+ },
+ under_maintenance: {
+ label: "Maintenance",
+ color: "bg-blue-500",
+ },
+} as const;
+
+// const SIZE = { width: 120, height: 34 };
+const SIZE: Record<string, { width: number; height: number }> = {
+ sm: { width: 120, height: 34 },
+ md: { width: 160, height: 46 },
+ lg: { width: 200, height: 56 },
+ xl: { width: 240, height: 68 },
+};
+export async function GET(
+ req: NextRequest,
+ props: { params: Promise<{ domain: string }> },
+) {
+ const params = await props.params;
+ const { status } = await getStatus(params.domain);
+ const theme = req.nextUrl.searchParams.get("theme");
+ const size = req.nextUrl.searchParams.get("size");
+ const s = SIZE[size ?? "sm"] ?? SIZE.sm;
+ const { label, color } = statusDictionary[status];
+ const light = "border-gray-200 text-gray-700 bg-white";
+ const dark = "border-gray-800 text-gray-300 bg-gray-900";
+
+ return new ImageResponse(
+ <div
+ tw={`flex items-center justify-center rounded-md border px-3 py-1
+ ${size === "sm" && "text-sm"}${size === "md" && "text-md"} ${
+ size === "lg" && "text-lg"
+ } ${size === "xl" && "text-xl"} ${!size && "text-sm"} ${
+ theme === "dark" ? dark : light
+ }`}
+ style={{ ...s }}
+ >
+ {label}
+ <div tw={`flex h-2 w-2 rounded-full ml-2 ${color}`} />
+ </div>,
+ { ...s },
+ );
+}
diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/badge/v2/route.ts b/apps/status-page/src/app/(status-page)/[domain]/(public)/badge/v2/route.ts
new file mode 100644
index 000000000..7bd80e6ae
--- /dev/null
+++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/badge/v2/route.ts
@@ -0,0 +1,95 @@
+import type { NextRequest } from "next/server";
+
+import type { Status } from "@openstatus/react";
+import { getStatus } from "@openstatus/react";
+
+const statusDictionary: Record<Status, { label: string; hexColor: string }> = {
+ operational: {
+ label: "All Systems Operational",
+ hexColor: "#10b981",
+ },
+ degraded_performance: {
+ label: "Degraded Performance",
+ hexColor: "#f59e0b",
+ },
+ partial_outage: {
+ label: "Partial Outage",
+ hexColor: "#f59e0b",
+ },
+ major_outage: {
+ label: "Major Outage",
+ hexColor: "#ef4444",
+ },
+ unknown: {
+ label: "Unknown",
+ hexColor: "#6b7280",
+ },
+ incident: {
+ label: "Ongoing Incident",
+ hexColor: "#f59e0b",
+ },
+ under_maintenance: {
+ label: "Under Maintenance",
+ hexColor: "#3b82f6",
+ },
+} as const;
+
+const SIZE: Record<
+ string,
+ {
+ height: number;
+ padding: number;
+ gap: number;
+ radius: number;
+ fontSize: number;
+ }
+> = {
+ sm: { height: 34, padding: 8, gap: 12, radius: 4, fontSize: 12 },
+ md: { height: 46, padding: 8, gap: 12, radius: 4, fontSize: 14 },
+ lg: { height: 56, padding: 12, gap: 16, radius: 6, fontSize: 16 },
+ xl: { height: 68, padding: 12, gap: 16, radius: 6, fontSize: 18 },
+};
+
+function getTextWidth(text: string, fontSize: number): number {
+ const monoCharWidthRatio = 0.6;
+ return text.length * monoCharWidthRatio * fontSize;
+}
+
+export async function GET(
+ req: NextRequest,
+ props: { params: Promise<{ domain: string }> },
+) {
+ const params = await props.params;
+ const { status } = await getStatus(params.domain);
+ const theme = req.nextUrl.searchParams.get("theme") ?? "light";
+ const variant = req.nextUrl.searchParams.get("variant") ?? "default";
+ const size = req.nextUrl.searchParams.get("size") ?? "sm";
+
+ const { height, padding, gap, radius, fontSize } = SIZE[size] ?? SIZE.sm;
+ const { label, hexColor } = statusDictionary[status];
+ const textWidth = getTextWidth(label, fontSize);
+ const width = Math.ceil(padding + textWidth + gap + radius * 2 + padding);
+
+ const textColor = theme === "dark" ? "#d1d5db" : "#374151";
+ const bgColor = theme === "dark" ? "#111827" : "#ffffff";
+ const borderColor = variant === "outline" ? "#d1d5db" : "transparent";
+
+ const svg = `
+ <svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">
+ <rect x="0.5" y="0.5" width="${width - 1}" height="${
+ height - 1
+ }" fill="${bgColor}" stroke="${borderColor}" stroke-width="1" rx="${radius}" ry="${radius}" />
+ <text x="${padding}" y="50%" dominant-baseline="middle"
+ font-family="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace" font-size="${fontSize}" font-weight="600" fill="${textColor}">
+ ${label}
+ </text>
+ <circle cx="${width - padding - radius}" cy="${
+ height / 2
+ }" r="${radius}" fill="${hexColor}"/>
+ </svg>
+ `;
+
+ return new Response(svg, {
+ headers: { "Content-Type": "image/svg+xml" },
+ });
+}
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index 9cfe0e757..f4a07016a 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -108,7 +108,7 @@ const nextConfig = {
},
{
source:
- "/:path((?!api|assets|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|feed|events|monitors|protected|verify).*)",
+ "/:path((?!api|assets|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|badge|feed|events|monitors|protected|verify).*)",
has: [
{ type: "cookie", key: "sp_mode", value: "new" },
{