Skip to content

Open-source status page, incident response and uptime monitoring

feat: first empty status page 📄 (#60)

Thibault Le Ouay303643662f05
diff --git a/apps/web/src/app/not-found.tsx b/apps/web/src/app/not-found.tsx
new file mode 100644
index 000000000..92c15812f
--- /dev/null
+++ b/apps/web/src/app/not-found.tsx
@@ -0,0 +1,16 @@
+import Link from "next/link";
+
+export default function NotFound() {
+ return (
+ <main className="flex min-h-screen w-full flex-col space-y-6 p-4 md:p-8">
+ <div className="flex flex-1 flex-col items-center justify-center gap-8">
+ <div className="mx-auto max-w-xl text-center">
+ <div className="border-border rounded-lg border p-8 backdrop-blur-[2px]">
+ <h2>Not Found 😭</h2>
+ <p>This page could not be found</p>
+ </div>
+ </div>
+ </div>
+ </main>
+ );
+}
diff --git a/apps/web/src/app/status-page/[domain]/page.tsx b/apps/web/src/app/status-page/[domain]/page.tsx
new file mode 100644
index 000000000..188062775
--- /dev/null
+++ b/apps/web/src/app/status-page/[domain]/page.tsx
@@ -0,0 +1,32 @@
+import { notFound } from "next/navigation";
+
+import { MonitorList } from "@/components/status-page/monitor-list";
+import { api } from "@/trpc/server";
+
+export default async function Page({ params }: { params: { domain: string } }) {
+ // We should fetch the the monitors and incident here
+ // also the page information
+ if (!params.domain) return notFound();
+ const page = await api.page.getPageBySlug.query({ slug: params.domain });
+ if (!page) {
+ return notFound();
+ }
+
+ return (
+ <main className="flex min-h-screen w-full flex-col space-y-6 p-4 md:p-8">
+ <div className="flex flex-1 flex-col items-center justify-center gap-8">
+ <div className="mx-auto max-w-xl text-center">
+ <div className="border-border rounded-lg border p-8 backdrop-blur-[2px]">
+ <h1 className="text-foreground font-cal mb-6 mt-2 text-3xl">
+ {page.title}
+ </h1>
+ <div>
+ <p className="text-muted-foreground">{page.description}</p>
+ </div>
+ </div>
+ <MonitorList monitors={page.monitors} />
+ </div>
+ </div>
+ </main>
+ );
+}
diff --git a/apps/web/src/components/status-page/monitor-list.tsx b/apps/web/src/components/status-page/monitor-list.tsx
new file mode 100644
index 000000000..c336d4356
--- /dev/null
+++ b/apps/web/src/components/status-page/monitor-list.tsx
@@ -0,0 +1,22 @@
+import type { z } from "zod";
+
+import type { selectMonitorSchema } from "@openstatus/db/src/schema";
+
+import { Monitor } from "./monitor";
+
+export const MonitorList = ({
+ monitors,
+}: {
+ monitors: z.infer<typeof selectMonitorSchema>[];
+}) => {
+ return (
+ <div>
+ {monitors.map((monitor, index) => (
+ <div key={index}>
+ {/* Fetch tracker and data */}
+ <Monitor monitor={monitor} />
+ </div>
+ ))}
+ </div>
+ );
+};
diff --git a/apps/web/src/components/status-page/monitor.tsx b/apps/web/src/components/status-page/monitor.tsx
new file mode 100644
index 000000000..750b80382
--- /dev/null
+++ b/apps/web/src/components/status-page/monitor.tsx
@@ -0,0 +1,28 @@
+import type { z } from "zod";
+
+import type { selectMonitorSchema } from "@openstatus/db/src/schema";
+
+import { getMonitorListData } from "@/lib/tb";
+import { Tracker } from "../monitor/tracker";
+
+export const Monitor = async ({
+ monitor,
+}: {
+ monitor: z.infer<typeof selectMonitorSchema>;
+}) => {
+ // fix this we should update our tinybird to fetch with pageId and monitorId
+ // const data = await getMonitorListData({ siteId: String(monitor.pageId) });
+ const data = await getMonitorListData({ siteId: "openstatus" });
+
+ return (
+ <div className="border-border rounded-lg border p-8">
+ <h1 className="font-cal mb-3 text-center text-2xl">Status</h1>
+ <Tracker
+ data={data}
+ id="openstatus"
+ name="Ping"
+ url="https://openstatus.dev/api/ping"
+ />
+ </div>
+ );
+};
diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.ts
index 03405293f..adc477393 100644
--- a/apps/web/src/middleware.ts
+++ b/apps/web/src/middleware.ts
@@ -1,11 +1,48 @@
+import type { NextFetchEvent, NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { authMiddleware, redirectToSignIn } from "@clerk/nextjs";
-import { createTRPCContext } from "@openstatus/api";
-import { edgeRouter } from "@openstatus/api/src/edge";
import { db, eq } from "@openstatus/db";
import { user, usersToWorkspaces } from "@openstatus/db/src/schema";
+const before = (req: NextRequest, ev: NextFetchEvent) => {
+ const url = req.nextUrl.clone();
+
+ if (url.pathname.includes("api/trpc")) {
+ return NextResponse.next();
+ }
+
+ const host = req.headers.get("host");
+ const subdomain = getValidSubdomain(host);
+ if (subdomain) {
+ // Subdomain available, rewriting
+ console.log(
+ `>>> Rewriting: ${url.pathname} to /status-page/${subdomain}${url.pathname}`,
+ );
+ url.pathname = `/status-page/${subdomain}${url.pathname}`;
+ return NextResponse.rewrite(url);
+ }
+
+ return NextResponse.next();
+};
+
+export const getValidSubdomain = (host?: string | null) => {
+ let subdomain: string | null = null;
+ if (!host && typeof window !== "undefined") {
+ // On client side, get the host from window
+ host = window.location.host;
+ }
+ // we should improve here for custom vercel deploy page
+ if (host && host.includes(".") && !host.includes(".ngrok-free.app")) {
+ const candidate = host.split(".")[0];
+ if (candidate && !candidate.includes("www")) {
+ // Valid candidate
+ subdomain = candidate;
+ }
+ }
+ return subdomain;
+};
+
export default authMiddleware({
publicRoutes: [
"/",
@@ -21,6 +58,8 @@ export default authMiddleware({
"/api/checker/regions/(.*)",
"/api/checker/cron/10m",
],
+
+ beforeAuth: before,
async afterAuth(auth, req, evt) {
// handle users who aren't authenticated
if (!auth.userId && !auth.isPublicRoute) {