Skip to content

Open-source status page, incident response and uptime monitoring

🚑 Middleware (#10)

Thibault Le Ouay5ca507cf629b
diff --git a/apps/web/src/app/api/v0/cron/route.ts b/apps/web/src/app/api/v0/cron/route.ts
index a62f8447b..5e6d1f839 100644
--- a/apps/web/src/app/api/v0/cron/route.ts
+++ b/apps/web/src/app/api/v0/cron/route.ts
@@ -1,5 +1,6 @@
+import { publishPingResponse, Tinybird } from "@openstatus/tinybird";
+
import { env } from "@/env.mjs";
-import { Tinybird, publishPingResponse } from "@openstatus/tinybird";
// TODO: create one route per region
export const preferredRegion = ["fra1"];
@@ -15,7 +16,7 @@ const tb = new Tinybird({ token: env.TINY_BIRD_API_KEY });
// TODO: create a package for monitor
async function monitor(
res: Response,
- { latency, url }: { latency: number; url: string }
+ { latency, url }: { latency: number; url: string },
) {
return await publishPingResponse(tb)({
id: "openstatus",
@@ -47,6 +48,7 @@ export async function GET(req: Request) {
return new Response("OK", { status: 200 });
} catch (e) {
+ console.error(e);
return new Response("Error", { status: 500 });
}
}
diff --git a/apps/web/src/app/api/v0/ping/route.ts b/apps/web/src/app/api/v0/ping/route.ts
index 60c1022ff..44e2e13a2 100644
--- a/apps/web/src/app/api/v0/ping/route.ts
+++ b/apps/web/src/app/api/v0/ping/route.ts
@@ -16,7 +16,8 @@ export async function GET(req: Request) {
"cache-control": "public, max-age=0, s-maxage=0",
},
});
- } catch {
+ } catch (e) {
+ console.error(e);
return new Response("Error", {
status: 500,
headers: {
diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.ts
index cdf9a4b0c..d2720dc26 100644
--- a/apps/web/src/middleware.ts
+++ b/apps/web/src/middleware.ts
@@ -3,8 +3,9 @@ import { authMiddleware } from "@clerk/nextjs";
export default authMiddleware({
publicRoutes: [
"/",
+ "/api/(.*)",
"/api/og",
- "/api/webhook/ping",
+ "/api/ping",
"/api/v0/cron",
"/api/v0/ping",
"/api/webhook/clerk",
@@ -12,5 +13,9 @@ export default authMiddleware({
});
export const config = {
- matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
+ matcher: [
+ "/((?!static|.*\\..*|_next|favicon.ico).*)",
+ "/",
+ "/(.*?trpc.*?|.*?api.*?)(.*)",
+ ],
};