const DEFAULT_ADMIN_HOST = "root.mohfarawati.de"; const DEFAULT_ADMIN_URL = `https://${DEFAULT_ADMIN_HOST}`; const DEFAULT_SITE_URL = "https://mohfarawati.de"; export const INTERNAL_ADMIN_PREFIX = "/_admin"; function normalizePathname(pathname: string): string { if (!pathname || pathname === "/") { return "/"; } return pathname.startsWith("/") ? pathname : `/${pathname}`; } function normalizeBaseUrl(url: string): string { return url.replace(/\/+$/, ""); } export function getAdminHost(): string { return (process.env.ADMIN_HOST ?? DEFAULT_ADMIN_HOST).trim().toLowerCase(); } export function getRequestHostname(hostHeader?: string | null): string { return (hostHeader ?? "") .split(",")[0] ?.trim() .toLowerCase() .replace(/:\d+$/, "") ?? ""; } export function isAdminHost(hostname: string): boolean { return hostname === getAdminHost(); } export function isLegacyAdminPath(pathname: string): boolean { return pathname === "/root" || pathname.startsWith("/root/"); } export function isInternalAdminPath(pathname: string): boolean { return pathname === INTERNAL_ADMIN_PREFIX || pathname.startsWith(`${INTERNAL_ADMIN_PREFIX}/`); } export function toInternalAdminPath(pathname: string): string { const normalizedPathname = normalizePathname(pathname); if (normalizedPathname === "/") { return INTERNAL_ADMIN_PREFIX; } return `${INTERNAL_ADMIN_PREFIX}${normalizedPathname}`; } export function getAdminBaseUrl(): string { return normalizeBaseUrl(process.env.NEXT_PUBLIC_ADMIN_URL ?? DEFAULT_ADMIN_URL); } export function buildAdminUrl(pathname = "/"): string { return `${getAdminBaseUrl()}${normalizePathname(pathname)}`; } export function getSiteBaseUrl(): string { return normalizeBaseUrl(process.env.NEXT_PUBLIC_SITE_URL ?? DEFAULT_SITE_URL); } export function buildSiteUrl(pathname = "/"): string { return `${getSiteBaseUrl()}${normalizePathname(pathname)}`; }