Skip to content

Open-source status page, incident response and uptime monitoring

chore: speed checker abort contoller (#1682)

Maximilian Kaske6f46bdba1ee6
diff --git a/apps/web/src/app/(landing)/play/checker/api/mock.ts b/apps/web/src/app/(landing)/play/checker/api/mock.ts
index 13859d408..fd7ffdf08 100644
--- a/apps/web/src/app/(landing)/play/checker/api/mock.ts
+++ b/apps/web/src/app/(landing)/play/checker/api/mock.ts
@@ -35,6 +35,7 @@ export const data = {
{
type: "http",
status: 200,
+ state: "success",
latency: 889,
headers: {
Age: "0",
diff --git a/apps/web/src/app/(landing)/play/checker/api/route.ts b/apps/web/src/app/(landing)/play/checker/api/route.ts
index 90fcbd9cf..8ce02b8b8 100644
--- a/apps/web/src/app/(landing)/play/checker/api/route.ts
+++ b/apps/web/src/app/(landing)/play/checker/api/route.ts
@@ -25,6 +25,7 @@ async function* makeIterator({
// Create an array to store all the promises
const promises = AVAILABLE_REGIONS.map(async (region, index) => {
try {
+ console.log(`Checking ${region}...`);
// Perform the fetch operation
const check =
process.env.NODE_ENV === "production"
diff --git a/apps/web/src/app/(landing)/play/checker/client.tsx b/apps/web/src/app/(landing)/play/checker/client.tsx
index 2a84c78d1..d57c313c1 100644
--- a/apps/web/src/app/(landing)/play/checker/client.tsx
+++ b/apps/web/src/app/(landing)/play/checker/client.tsx
@@ -123,20 +123,27 @@ export function Form({
startTransition(async () => {
async function fetchAndReadStream() {
+ let toastId: string | number | undefined;
try {
- const toastId = toast.loading("Loading data from regions...", {
+ toastId = toast.loading("Loading data from regions...", {
duration: Number.POSITIVE_INFINITY,
closeButton: false,
});
+ const abortController = new AbortController();
+ const timeoutId = setTimeout(() => abortController.abort(), 10_000);
+
const response = await fetch("/play/checker/api", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ url, method }),
+ signal: abortController.signal,
});
+ clearTimeout(timeoutId);
+
const reader = response?.body?.getReader();
if (!reader) return;
@@ -206,7 +213,14 @@ export function Form({
}
} catch (error) {
console.error("Error fetching data:", error);
- // Could add error handling/toast here
+ if (error instanceof Error && error.name === "AbortError") {
+ toast.error("Request timeout", {
+ id: toastId,
+ description:
+ "The request took too long and was aborted after 7 seconds.",
+ className: "text-destructive!",
+ });
+ }
}
}
diff --git a/apps/web/src/app/api/og/status/route.tsx b/apps/web/src/app/api/og/status/route.tsx
new file mode 100644
index 000000000..2cbe1dc5e
--- /dev/null
+++ b/apps/web/src/app/api/og/status/route.tsx
@@ -0,0 +1,126 @@
+import { ImageResponse } from "next/og";
+
+import { DESCRIPTION, TITLE } from "@/app/shared-metadata";
+import { cn } from "@/lib/utils";
+import { api } from "@/trpc/server";
+import type { RouterOutputs } from "@openstatus/api";
+import { format } from "date-fns";
+import { SIZE } from "../utils";
+
+export const runtime = "edge";
+
+const FOOTER = "openstatus.dev";
+
+type Page = NonNullable<RouterOutputs["statusPage"]["get"]>;
+
+function getContent(page?: Page | null) {
+ switch (page?.status) {
+ case "error":
+ return {
+ label: "Incident Ongoing",
+ bg: "bg-rose-500/90 border-rose-500",
+ text: "text-rose-500",
+ };
+ case "degraded":
+ return {
+ label: "Degraded Performance",
+ bg: "bg-orange-500/90 border-orange-500",
+ text: "text-amber-500",
+ };
+ case "info":
+ return {
+ label: "Maintenance",
+ bg: "bg-blue-500/90 border-blue-500",
+ text: "text-blue-500",
+ };
+ case "success":
+ return {
+ label: "All Systems Operational",
+ bg: "bg-green-500/90 border-green-500",
+ text: "text-green-500",
+ };
+ default:
+ return {
+ label: "Unknown",
+ bg: "bg-gray-500/90 border-gray-500",
+ text: "text-gray-500",
+ };
+ }
+}
+
+export async function GET(req: Request) {
+ const fontMonoRegular = await fetch(
+ new URL("../../../../public/fonts/RobotoMono-Regular.ttf", import.meta.url),
+ ).then((res) => res.arrayBuffer());
+ const fontMonoMedium = await fetch(
+ new URL("../../../../public/fonts/RobotoMono-Medium.ttf", import.meta.url),
+ ).then((res) => res.arrayBuffer());
+ const fontMonoBold = await fetch(
+ new URL("../../../../public/fonts/RobotoMono-Bold.ttf", import.meta.url),
+ ).then((res) => res.arrayBuffer());
+
+ const { searchParams } = new URL(req.url);
+
+ const slug = searchParams.has("slug") ? searchParams.get("slug") : undefined;
+
+ const page = await api.statusPage.get.query({ slug: slug || "" });
+ const content = getContent(page);
+
+ const title = page ? page.title : TITLE;
+ const description = page ? page.description : DESCRIPTION;
+ const category = content?.label || "unknown";
+ const footer =
+ page?.customDomain || page ? `${page?.slug}.openstatus.dev` : FOOTER;
+
+ return new ImageResponse(
+ <div tw="relative flex flex-col items-start justify-start w-full h-full bg-gray-100">
+ <div
+ tw="flex flex-col h-full p-8 w-full"
+ style={{ fontFamily: "Font Mono" }}
+ >
+ <div tw="flex flex-col justify-end flex-1 mb-8">
+ <div tw={cn("flex flex-row items-center text-2xl", content?.text)}>
+ [<div tw={cn("rounded-full h-5 w-5 mr-2", content?.bg)} />
+ <p>{category}</p>] | {format(new Date(), "MMM d, yyyy HH:mm zzz")}
+ </div>
+ <h1
+ tw="text-6xl text-black text-left font-medium"
+ style={{ lineClamp: 2, display: "block" }}
+ >
+ {title}
+ </h1>
+ <p
+ tw="text-4xl text-slate-700 text-left"
+ style={{ lineClamp: 2, display: "block" }}
+ >
+ {description}
+ </p>
+ </div>
+ <p tw="font-medium text-xl text-slate-500 text-left">{footer}</p>
+ </div>
+ </div>,
+ {
+ ...SIZE,
+ fonts: [
+ {
+ name: "Font Mono",
+ data: fontMonoRegular,
+ style: "normal",
+ weight: 400,
+ },
+ {
+ name: "Font Mono",
+ data: fontMonoMedium,
+ style: "normal",
+ weight: 500,
+ },
+ {
+ name: "Font Mono",
+ data: fontMonoBold,
+ style: "normal",
+ weight: 700,
+ },
+ ],
+ },
+ );
+}
diff --git a/apps/web/src/content/cmdk.tsx b/apps/web/src/content/cmdk.tsx
index 6a9660d0f..e9d08eb14 100644
--- a/apps/web/src/content/cmdk.tsx
+++ b/apps/web/src/content/cmdk.tsx
@@ -272,7 +272,7 @@ export function CmdK() {
</kbd>
</button>
<Dialog open={open} onOpenChange={setOpen}>
- <DialogContent className="overflow-hidden rounded-none p-0 font-mono shadow-2xl top-[15%] translate-y-0">
+ <DialogContent className="top-[15%] translate-y-0 overflow-hidden rounded-none p-0 font-mono shadow-2xl">
<DialogTitle className="sr-only">Search</DialogTitle>
<Command
onKeyDown={(e) => {