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.
2.0 kB ยท 57 lines
TypeScript
at incident-api
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import { 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, pathname, customDomain, locale, defaultLocale,}: { hostname: string; pathname: string; customDomain: string | undefined; locale: string; defaultLocale: string;}): string { const hostnames = hostname.split("."); const isCustomDomain = customDomain ? hostname === customDomain : false;
// acme.localhost:3000 โ ["acme", "localhost:3000"] (length 2, but is a subdomain) // acme.stpg.dev โ ["acme", "stpg", "dev"] (length 3+) // localhost:3000 โ ["localhost:3000"] (length 1, pathname routing) const hasLocalhostSubdomain = hostnames.length === 2 && /^localhost(:\d+)?$/.test(hostnames[1]); const isSubdomain = (hostnames.length > 2 || hasLocalhostSubdomain) && hostnames[0] !== "www" && !hostname.endsWith(".vercel.app");
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} return `${firstSegment}/${locale}`;}