Move admin area to root subdomain
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-03-12 00:15:12 +01:00
parent e7dab6f0ef
commit 87a597c872
50 changed files with 256 additions and 140 deletions
+67
View File
@@ -0,0 +1,67 @@
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)}`;
}
+13 -13
View File
@@ -42,56 +42,56 @@ export function getRootNavigation(
return [
{
label: copy.overview,
href: "/root",
href: "/",
icon: LayoutDashboard,
active: active === "overview",
},
{
label: copy.maintenance,
href: "/root/maintenance",
href: "/maintenance",
icon: ShieldAlert,
active: active === "maintenance",
},
{
label: copy.uiKit,
href: "/root/ui-kit",
href: "/ui-kit",
icon: SwatchBook,
active: active === "ui-kit",
},
{
label: copy.media,
href: "/root/media",
href: "/media",
icon: ImageIcon,
active: active === "media",
},
{
label: copy.siteSettings,
href: "/root/site-settings",
href: "/site-settings",
icon: Globe2,
active: active === "site-settings",
},
{
label: copy.marquee ?? "Marquee",
href: "/root/marquee",
href: "/marquee",
icon: Type,
active: active === "marquee",
},
{
label: copy.smtp ?? "SMTP",
href: "/root/smtp",
href: "/smtp",
icon: Mail,
active: active === "smtp" && !smtpChild,
expanded: active === "smtp",
children: [
{
label: copy.smtp ?? "SMTP",
href: "/root/smtp",
href: "/smtp",
icon: Mail,
active: smtpChild === "settings" || (!smtpChild && active === "smtp"),
},
{
label: copy.contactProtection ?? "Contact Protection",
href: "/root/smtp/contact-protection",
href: "/smtp/contact-protection",
icon: ShieldAlert,
active: smtpChild === "contact-protection",
},
@@ -99,26 +99,26 @@ export function getRootNavigation(
},
{
label: copy.portfolio,
href: "/root/portfolio",
href: "/portfolio",
icon: FolderKanban,
active: active === "portfolio" && !portfolioChild,
expanded: active === "portfolio",
children: [
{
label: "Projects",
href: "/root/portfolio",
href: "/portfolio",
icon: FolderKanban,
active: portfolioChild === "overview" || portfolioChild === "projects",
},
{
label: "Add Project",
href: "/root/portfolio/projects/new",
href: "/portfolio/projects/new",
icon: PlusSquare,
active: portfolioChild === "new-project",
},
{
label: "Add Category",
href: "/root/portfolio/categories",
href: "/portfolio/categories",
icon: Tags,
active: portfolioChild === "categories",
},