Skip to content

Open-source status page, incident response and uptime monitoring

fix(status-page): keep the full path on host-keyed status pages (#2585)

Maximilian Kaske8f5590c2a985
diff --git a/apps/status-page/src/lib/resolve-route.test.ts b/apps/status-page/src/lib/resolve-route.test.ts
index 39046b508..0ca871828 100644
--- a/apps/status-page/src/lib/resolve-route.test.ts
+++ b/apps/status-page/src/lib/resolve-route.test.ts
@@ -364,6 +364,136 @@ describe("resolveRoute", () => {
});
});
+ // Custom domains with fewer than three labels, or a "www." first label, are
+ // still host-keyed: the path must not be read as `/{slug}/...`.
+ describe('custom domain routing — apex and "www." hosts', () => {
+ test("acme.com/events/report/1 → hostname routing, path preserved", () => {
+ const result = resolveRoute({
+ host: "acme.com",
+ urlHost: "acme.com",
+ pathname: "/events/report/1",
+ });
+ expect(result).toEqual({
+ type: "hostname",
+ prefix: "acme.com",
+ locale: "en",
+ localeExplicit: false,
+ rewritePath: "/acme.com/en/events/report/1",
+ });
+ });
+
+ test("acme.com/fr/events/maintenance/1 → explicit locale, path preserved", () => {
+ const result = resolveRoute({
+ host: "acme.com",
+ urlHost: "acme.com",
+ pathname: "/fr/events/maintenance/1",
+ });
+ expect(result).toEqual({
+ type: "hostname",
+ prefix: "acme.com",
+ locale: "fr",
+ localeExplicit: true,
+ rewritePath: "/acme.com/fr/events/maintenance/1",
+ });
+ });
+
+ test("www.acme.com/monitors/1 → hostname routing, path preserved", () => {
+ const result = resolveRoute({
+ host: "www.acme.com",
+ urlHost: "www.acme.com",
+ pathname: "/monitors/1",
+ });
+ expect(result).toEqual({
+ type: "hostname",
+ prefix: "www.acme.com",
+ locale: "en",
+ localeExplicit: false,
+ rewritePath: "/www.acme.com/en/monitors/1",
+ });
+ });
+ });
+
+ // apps/web proxies a custom domain as `https://www.stpg.dev/{host}/{rest}`
+ // while forwarding the original host, so the leading segment is redundant.
+ describe("custom domain routing — host also present as path prefix", () => {
+ test("status.acme.com + /status.acme.com/events/report/1 → segment not duplicated", () => {
+ const result = resolveRoute({
+ host: "status.acme.com",
+ urlHost: "www.stpg.dev",
+ pathname: "/status.acme.com/events/report/1",
+ });
+ expect(result).toEqual({
+ type: "hostname",
+ prefix: "status.acme.com",
+ locale: "en",
+ localeExplicit: false,
+ rewritePath: "/status.acme.com/en/events/report/1",
+ });
+ });
+
+ test("status.acme.com + /status.acme.com/fr/events → locale read after the prefix", () => {
+ const result = resolveRoute({
+ host: "status.acme.com",
+ urlHost: "www.stpg.dev",
+ pathname: "/status.acme.com/fr/events",
+ });
+ expect(result).toEqual({
+ type: "hostname",
+ prefix: "status.acme.com",
+ locale: "fr",
+ localeExplicit: true,
+ rewritePath: "/status.acme.com/fr/events",
+ });
+ });
+
+ test("status.acme.com + /status.acme.com → page root", () => {
+ const result = resolveRoute({
+ host: "status.acme.com",
+ urlHost: "www.stpg.dev",
+ pathname: "/status.acme.com",
+ });
+ expect(result).toEqual({
+ type: "hostname",
+ prefix: "status.acme.com",
+ locale: "en",
+ localeExplicit: false,
+ rewritePath: "/status.acme.com/en",
+ });
+ });
+
+ test("subdomain + /acme.openstatus.dev/events → forwarded host stripped", () => {
+ const result = resolveRoute({
+ host: "acme.openstatus.dev",
+ urlHost: "www.stpg.dev",
+ pathname: "/acme.openstatus.dev/events",
+ });
+ expect(result).toEqual({
+ type: "hostname",
+ prefix: "acme",
+ locale: "en",
+ localeExplicit: false,
+ rewritePath: "/acme/en/events",
+ });
+ });
+
+ // Only the host is stripped: a first segment that merely matches the slug is
+ // real path, e.g. a page whose slug is also a route name.
+ test('slug "monitors" + /monitors/1 → segment kept', () => {
+ const result = resolveRoute({
+ host: "monitors.stpg.dev",
+ urlHost: "monitors.stpg.dev",
+ pathname: "/monitors/1",
+ });
+ expect(result).toEqual({
+ type: "hostname",
+ prefix: "monitors",
+ locale: "en",
+ localeExplicit: false,
+ rewritePath: "/monitors/en/monitors/1",
+ });
+ });
+ });
+
describe("edge cases", () => {
test("root path on localhost returns null (no page)", () => {
const result = resolveRoute({
diff --git a/apps/status-page/src/lib/resolve-route.ts b/apps/status-page/src/lib/resolve-route.ts
index 2e2804879..427f817ca 100644
--- a/apps/status-page/src/lib/resolve-route.ts
+++ b/apps/status-page/src/lib/resolve-route.ts
@@ -1,5 +1,5 @@
import { type Locale, defaultLocale, locales } from "../i18n/config";
-import { getValidSubdomain } from "./domain";
+import { getValidSubdomain, stripHostPort } from "./domain";
export type RouteType = "hostname" | "pathname";
@@ -53,6 +53,10 @@ export function resolveRoute({
if (subdomain !== null) {
prefix = subdomain.toLowerCase();
+ // Host-keyed: the path carries no slug. Apex (`acme.com`) and `www.` custom
+ // domains fail the label check above, and reading their first segment as the
+ // slug would drop it (`/events/report/1` → `/{slug}/{locale}/report/1`).
+ type = "hostname";
}
// Root path on non-hostname type — no page to resolve
@@ -69,12 +73,21 @@ export function resolveRoute({
// Resolve locale based on routing type
if (type === "hostname") {
- const firstSegment = pathnames[1]?.toLowerCase();
+ // apps/web proxies custom domains as `https://www.stpg.dev/{host}/{rest}`
+ // and forwards the original host, so drop a leading segment that repeats
+ // the prefix — keeping it duplicates the domain inside the rewrite path.
+ const hostSegment = stripHostPort(host ?? urlHost)?.toLowerCase();
+ const segments =
+ pathnames[1]?.toLowerCase() === hostSegment
+ ? pathnames.slice(1)
+ : pathnames;
+
+ const firstSegment = segments[1]?.toLowerCase();
const locale: Locale = isLocale(firstSegment)
? firstSegment
: defaultLocale;
const hasLocale = isLocale(firstSegment);
- const rest = (hasLocale ? pathnames.slice(2) : pathnames.slice(1))
+ const rest = (hasLocale ? segments.slice(2) : segments.slice(1))
.filter(Boolean)
.join("/");