Skip to content

Open-source status page, incident response and uptime monitoring

fix(status-page): keep slug prefix in links on subdomain-shaped hosts (#2594)

Harsh Kumar734bc44af73d
diff --git a/apps/status-page/src/lib/resolve-pathname-prefix.test.ts b/apps/status-page/src/lib/resolve-pathname-prefix.test.ts
index 85e9d9b70..e76cf185f 100644
--- a/apps/status-page/src/lib/resolve-pathname-prefix.test.ts
+++ b/apps/status-page/src/lib/resolve-pathname-prefix.test.ts
@@ -156,6 +156,123 @@ describe("resolvePathnamePrefix", () => {
});
});
+ describe("subdomain-shaped host that owns no page", () => {
+ // `themes.openstatus.dev` is the theme explorer: subdomain-shaped, but it
+ // owns no page of its own, so its demo page is served from
+ // `/status/{locale}` and its links must keep the slug prefix.
+ test("keeps the prefix on the explorer's status page", () => {
+ expect(
+ resolvePathnamePrefix({
+ hostname: "themes.openstatus.dev",
+ pathname: "/status/en",
+ customDomain: undefined,
+ locale: "en",
+ defaultLocale,
+ }),
+ ).toBe("status/en");
+ });
+
+ test("keeps the prefix on a deep path with a non-default locale", () => {
+ expect(
+ resolvePathnamePrefix({
+ hostname: "themes.openstatus.dev",
+ pathname: "/status/fr/monitors/123",
+ customDomain: undefined,
+ locale: "fr",
+ defaultLocale,
+ }),
+ ).toBe("status/fr");
+ });
+
+ test("keeps the prefix when the locale segment is absent", () => {
+ expect(
+ resolvePathnamePrefix({
+ hostname: "themes.openstatus.dev",
+ pathname: "/status",
+ customDomain: undefined,
+ locale: "en",
+ defaultLocale,
+ }),
+ ).toBe("status/en");
+ });
+
+ test("matches the slug segment case-insensitively", () => {
+ expect(
+ resolvePathnamePrefix({
+ hostname: "themes.openstatus.dev",
+ pathname: "/Status/en",
+ customDomain: undefined,
+ locale: "en",
+ defaultLocale,
+ }),
+ ).toBe("Status/en");
+ });
+
+ test("only the `status` slug is prefixed — the explorer root is not", () => {
+ expect(
+ resolvePathnamePrefix({
+ hostname: "themes.openstatus.dev",
+ pathname: "/",
+ customDomain: undefined,
+ locale: "fr",
+ defaultLocale,
+ }),
+ ).toBe("fr");
+ });
+
+ test("only the `status` slug is prefixed — other slugs are not", () => {
+ expect(
+ resolvePathnamePrefix({
+ hostname: "themes.openstatus.dev",
+ pathname: "/acme/en",
+ customDomain: undefined,
+ locale: "en",
+ defaultLocale,
+ }),
+ ).toBe("");
+ });
+ });
+
+ describe("hostname-routed pages are unaffected", () => {
+ test("a subdomain page keeps dropping the prefix", () => {
+ expect(
+ resolvePathnamePrefix({
+ hostname: "acme.openstatus.dev",
+ pathname: "/events",
+ customDomain: undefined,
+ locale: "en",
+ defaultLocale,
+ }),
+ ).toBe("");
+ });
+
+ test("a subdomain page whose own slug is `status`", () => {
+ // Only the explorer host opts into the prefix, so a real page at
+ // `status.openstatus.dev/status` still drops it.
+ expect(
+ resolvePathnamePrefix({
+ hostname: "status.openstatus.dev",
+ pathname: "/status",
+ customDomain: undefined,
+ locale: "fr",
+ defaultLocale,
+ }),
+ ).toBe("fr");
+ });
+
+ test("a custom domain page keeps dropping the prefix", () => {
+ expect(
+ resolvePathnamePrefix({
+ hostname: "status.acme.com",
+ pathname: "/status",
+ customDomain: "status.acme.com",
+ locale: "fr",
+ defaultLocale,
+ }),
+ ).toBe("fr");
+ });
+ });
+
describe("edge cases", () => {
test("www subdomain is treated as pathname routing", () => {
expect(
diff --git a/apps/status-page/src/lib/resolve-pathname-prefix.ts b/apps/status-page/src/lib/resolve-pathname-prefix.ts
index 31a7f6ca6..ed873095b 100644
--- a/apps/status-page/src/lib/resolve-pathname-prefix.ts
+++ b/apps/status-page/src/lib/resolve-pathname-prefix.ts
@@ -1,8 +1,15 @@
+import {
+ THEME_EXPLORER_PAGE_SLUG,
+ isCanonicalThemeExplorerHost,
+} from "./theme-explorer-host";
+
/**
* Computes the prefix used for client-side navigation links.
*
* - Hostname routing (subdomain / custom domain): locale only (empty for default)
* - Pathname routing: always `{slug}/{locale}`
+ * - The theme explorer host is subdomain-shaped but owns no page, so its own
+ * demo page at `/status/{locale}` is pathname routed
*/
export function resolvePathnamePrefix({
hostname,
@@ -30,12 +37,21 @@ export function resolvePathnamePrefix({
hostnames[0] !== "www" &&
!hostname.endsWith(".vercel.app");
- if (isCustomDomain || isSubdomain) {
+ const firstSegment = pathname.split("/")[1] || "";
+
+ // The theme explorer host is subdomain-shaped but owns no page of its own —
+ // its demo page is served from `/status/{locale}`, so links there keep the
+ // slug prefix instead of dropping it like a real subdomain page would. Only
+ // the canonical host serves that page, so it alone opts in.
+ const isThemeExplorerPage =
+ isCanonicalThemeExplorerHost(hostname) &&
+ firstSegment.toLowerCase() === THEME_EXPLORER_PAGE_SLUG;
+
+ if (!isThemeExplorerPage && (isCustomDomain || isSubdomain)) {
// Subdomain or custom domain — no slug prefix needed
return locale !== defaultLocale ? locale : "";
}
// Pathname routing — always {slug}/{locale}
- const slug = pathname.split("/")[1] || "";
- return `${slug}/${locale}`;
+ return `${firstSegment}/${locale}`;
}
diff --git a/apps/status-page/src/lib/theme-explorer-host.ts b/apps/status-page/src/lib/theme-explorer-host.ts
index b43c9734a..f2fb1ef2e 100644
--- a/apps/status-page/src/lib/theme-explorer-host.ts
+++ b/apps/status-page/src/lib/theme-explorer-host.ts
@@ -4,6 +4,9 @@ import { stripHostPort } from "./domain";
export const THEME_EXPLORER_HOST = "themes.openstatus.dev";
export const THEME_EXPLORER_URL = `https://${THEME_EXPLORER_HOST}`;
+/** The only page the explorer host serves, at `/status/{locale}`. */
+export const THEME_EXPLORER_PAGE_SLUG = "status";
+
// The explorer lives at `/`, which is also where every unresolved host lands
// (unknown slug, custom domain pointed at us but missing from `page`). Without
// this allowlist those hosts render — and share — the explorer as their 404.