Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
8.5 kB ยท 314 lines
TypeScript
at incident-api
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315import { expect } from "@std/expect";import { describe, test } from "@std/testing/bdd";
import { resolvePathnamePrefix } from "./resolve-pathname-prefix";
const defaultLocale = "en";
describe("resolvePathnamePrefix", () => { describe("hostname routing (subdomain)", () => { test("acme.localhost:3000 + en โ empty (default locale)", () => { expect( resolvePathnamePrefix({ hostname: "acme.localhost", pathname: "/", customDomain: undefined, locale: "en", defaultLocale, }), ).toBe(""); });
test("acme.localhost:3000 + fr โ 'fr'", () => { expect( resolvePathnamePrefix({ hostname: "acme.localhost", pathname: "/", customDomain: undefined, locale: "fr", defaultLocale, }), ).toBe("fr"); });
test("acme.localhost:3000/events + fr โ 'fr'", () => { expect( resolvePathnamePrefix({ hostname: "acme.localhost", pathname: "/events", customDomain: undefined, locale: "fr", defaultLocale, }), ).toBe("fr"); }); });
describe("custom domain routing", () => { test("status.acme.com + en โ empty (default locale)", () => { expect( resolvePathnamePrefix({ hostname: "status.acme.com", pathname: "/", customDomain: "status.acme.com", locale: "en", defaultLocale, }), ).toBe(""); });
test("status.acme.com + fr โ 'fr'", () => { expect( resolvePathnamePrefix({ hostname: "status.acme.com", pathname: "/", customDomain: "status.acme.com", locale: "fr", defaultLocale, }), ).toBe("fr"); });
test("status.acme.com/monitors/1 + en โ empty", () => { expect( resolvePathnamePrefix({ hostname: "status.acme.com", pathname: "/monitors/1", customDomain: "status.acme.com", locale: "en", defaultLocale, }), ).toBe(""); }); });
describe("pathname routing", () => { test("localhost + /acme + en โ 'acme/en'", () => { expect( resolvePathnamePrefix({ hostname: "localhost", pathname: "/acme", customDomain: undefined, locale: "en", defaultLocale, }), ).toBe("acme/en"); });
test("localhost + /acme + fr โ 'acme/fr'", () => { expect( resolvePathnamePrefix({ hostname: "localhost", pathname: "/acme", customDomain: undefined, locale: "fr", defaultLocale, }), ).toBe("acme/fr"); });
test("localhost + /acme/en/events + en โ 'acme/en'", () => { expect( resolvePathnamePrefix({ hostname: "localhost", pathname: "/acme/en/events", customDomain: undefined, locale: "en", defaultLocale, }), ).toBe("acme/en"); });
test("localhost + /acme/fr/monitors/123 + fr โ 'acme/fr'", () => { expect( resolvePathnamePrefix({ hostname: "localhost", pathname: "/acme/fr/monitors/123", customDomain: undefined, locale: "fr", defaultLocale, }), ).toBe("acme/fr"); });
test("localhost + /status + en โ 'status/en'", () => { expect( resolvePathnamePrefix({ hostname: "localhost", pathname: "/status", customDomain: undefined, locale: "en", defaultLocale, }), ).toBe("status/en"); });
test("localhost + /status/fr/events + fr โ 'status/fr'", () => { expect( resolvePathnamePrefix({ hostname: "localhost", pathname: "/status/fr/events", customDomain: undefined, locale: "fr", defaultLocale, }), ).toBe("status/fr"); }); });
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( resolvePathnamePrefix({ hostname: "www.openstatus.dev", pathname: "/acme", customDomain: undefined, locale: "en", defaultLocale, }), ).toBe("acme/en"); });
test("vercel.app preview is treated as pathname routing", () => { expect( resolvePathnamePrefix({ hostname: "my-app.vercel.app", pathname: "/acme", customDomain: undefined, locale: "fr", defaultLocale, }), ).toBe("acme/fr"); });
test("no custom domain match falls through to hostname check", () => { // hostname has 3+ segments but customDomain doesn't match expect( resolvePathnamePrefix({ hostname: "acme.openstatus.dev", pathname: "/", customDomain: "other.domain.com", locale: "fr", defaultLocale, }), ).toBe("fr"); }); });});