Openstatus
www.openstatus.dev
1import { ImageResponse } from "next/og";
2
3import { OSTinybird } from "@openstatus/tinybird";
4
5import { DESCRIPTION, TITLE } from "@/app/shared-metadata";
6import { env } from "@/env";
7import { BasicLayout } from "../_components/basic-layout";
8import { Tracker } from "../_components/tracker";
9import { SIZE, calSemiBold, interLight, interRegular } from "../utils";
10
11const tb = new OSTinybird(env.TINY_BIRD_API_KEY);
12
13export const runtime = "edge";
14
15export async function GET(req: Request) {
16 const [interRegularData, interLightData, calSemiBoldData] = await Promise.all(
17 [interRegular, interLight, calSemiBold],
18 );
19
20 const { searchParams } = new URL(req.url);
21
22 const title =
23 (searchParams.has("title") && searchParams.get("title")) || TITLE;
24
25 const description =
26 (searchParams.has("description") && searchParams.get("description")) ||
27 DESCRIPTION;
28
29 const monitorId =
30 (searchParams.has("id") && searchParams.get("id")) || undefined;
31
32 // TODO: we need to pass the monitor type here
33
34 const res = (monitorId &&
35 (await tb.legacy_httpStatus45d({
36 monitorId,
37 }))) || { data: [] };
38
39 return new ImageResponse(
40 <BasicLayout
41 title={title}
42 description={description}
43 tw={res.data.length === 0 ? "mt-32" : undefined}
44 >
45 {res.data.length ? <Tracker data={res.data} /> : null}
46 </BasicLayout>,
47 {
48 ...SIZE,
49 fonts: [
50 {
51 name: "Inter",
52 data: interRegularData,
53 style: "normal",
54 weight: 400,
55 },
56 {
57 name: "Inter",
58 data: interLightData,
59 style: "normal",
60 weight: 300,
61 },
62 {
63 name: "Cal",
64 data: calSemiBoldData,
65 style: "normal",
66 weight: 600,
67 },
68 ],
69 },
70 );
71}