Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
wtf: rewrite
Maximilian Kaskef30cb08055dd
diff --git a/apps/status-page/src/middleware.ts b/apps/status-page/src/middleware.tsindex 5213639df..fad7bf6aa 100644--- a/apps/status-page/src/middleware.ts+++ b/apps/status-page/src/middleware.ts@@ -84,30 +84,6 @@ export default async function middleware(req: NextRequest) {return NextResponse.rewrite(new URL(`/${prefix}${url.pathname}`, req.url));}- // NOTE - WORKING ON CUSTOM DOMAIN!!!-- // WTF is this- if (_page.customDomain === prefix && pathnames[1] === pathnames[2]) {- const newPathname = `/${pathnames.slice(2).join("/")}`;- console.log("newPath", newPathname);- console.log(pathnames);- return NextResponse.rewrite(new URL(`${pathnames[1]}`, req.url));- }-- // WTF is this- if (- _page.customDomain === prefix &&- (pathnames[2] === "assets" ||- pathnames[2] === "api" ||- pathnames[2] === "_next" ||- pathnames[2] === "favicon.ico" ||- pathnames[2] === "robots.txt" ||- pathnames[2] === "sitemap.xml")- ) {- const newPathname = `/${pathnames.slice(2).join("/")}`;- return NextResponse.rewrite(new URL(newPathname, req.url));- }-return response;}diff --git a/apps/web/next.config.js b/apps/web/next.config.jsindex cd63d9df7..10551d9a3 100644--- a/apps/web/next.config.js+++ b/apps/web/next.config.js@@ -98,13 +98,14 @@ const nextConfig = {source: "/:path*",has: [{ type: "cookie", key: "sp_mode", value: "new" },+ { type: "cookie", key: "sp_slug", value: "<slug>" },{type: "host",value:"^(?!.*\\.openstatus\\.dev$)(?!openstatus\\.dev$)(?<domain>.+)$",},],- destination: "https://www.stpg.dev/:domain/:path*",+ destination: "https://:slug.stpg.dev/:path*",},],};diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.tsindex 2820b2ff6..dd80be013 100644--- a/apps/web/src/middleware.ts+++ b/apps/web/src/middleware.ts@@ -9,7 +9,7 @@ import { eq } from "@openstatus/db";import { Redis } from "@openstatus/upstash";import { env } from "./env";-const MAX_AGE = 60 * 10; // 10 minutes+const MAX_AGE = 30; // 30 secondsexport const getValidSubdomain = (host?: string | null) => {let subdomain: string | null = null;@@ -71,19 +71,23 @@ export default auth(async (req) => {const modeCookie = req.cookies.get("sp_mode")?.value; // "legacy" | "new"const cached = modeCookie === "legacy" || modeCookie === "new";let mode: "legacy" | "new" | undefined = cached ? modeCookie : undefined;+ let slug: string | undefined = undefined;console.log({ mode, cached });if (!mode) {try {const redis = Redis.fromEnv();+ // NOTE: we are storing the slug in the cache if it's the new status pageconst cache = await redis.get(`page:${subdomain}`);console.log({ cache });// Determine legacy flag from cachemode = cache ? "new" : "legacy";+ slug = cache ? String(cache) : undefined;} catch (e) {console.error("error getting cache", e);mode = "legacy";+ slug = undefined;}}@@ -99,7 +103,9 @@ export default auth(async (req) => {res.headers.set("x-proxy", "1");// Short-lived cookie so toggles apply relatively quicklyres.cookies.set("sp_mode", "new", { path: "/", maxAge: MAX_AGE });-+ if (slug) {+ res.cookies.set("sp_slug", slug, { path: "/", maxAge: MAX_AGE });+ }// If we just set the cookie, trigger one redirect so next.config.js// rewrites that depend on sp_mode can apply on the next request.if (!cached) {