Skip to content

Open-source status page, incident response and uptime monitoring

1.9 KB
Raw Blame
import { OSTinybird } from "@openstatus/tinybird";
import { ImageResponse } from "next/og";

import { env } from "../../../../env";
import { DESCRIPTION, TITLE } from "../../../../lib/metadata/shared-metadata";
import { BasicLayout } from "../_components/basic-layout";
import { Tracker } from "../_components/tracker";
import { SIZE, calSemiBold, interLight, interRegular } from "../utils";

const tb = new OSTinybird({
  token: env.TINY_BIRD_API_KEY,
  baseUrl: env.TINYBIRD_URL,
  noop: env.TINYBIRD_NOOP,
});

export const runtime = "edge";

export async function GET(req: Request) {
  const [interRegularData, interLightData, calSemiBoldData] = await Promise.all(
    [interRegular, interLight, calSemiBold],
  );

  const { searchParams } = new URL(req.url);

  const title =
    (searchParams.has("title") && searchParams.get("title")) || TITLE;

  const description =
    (searchParams.has("description") && searchParams.get("description")) ||
    DESCRIPTION;

  const monitorId =
    (searchParams.has("id") && searchParams.get("id")) || undefined;

  // TODO: we need to pass the monitor type here

  const res = (monitorId &&
    (await tb.legacy_httpStatus45d({
      monitorId,
    }))) || { data: [] };

  return new ImageResponse(
    <BasicLayout
      title={title}
      description={description}
      tw={res.data.length === 0 ? "mt-32" : undefined}
    >
      {res.data.length ? <Tracker data={res.data} /> : null}
    </BasicLayout>,
    {
      ...SIZE,
      fonts: [
        {
          name: "Inter",
          data: interRegularData,
          style: "normal",
          weight: 400,
        },
        {
          name: "Inter",
          data: interLightData,
          style: "normal",
          weight: 300,
        },
        {
          name: "Cal",
          data: calSemiBoldData,
          style: "normal",
          weight: 600,
        },
      ],
    },
  );
}