import { headers } from "next/headers"; /** * Resolve the current site domain from request headers. * Used by the theme resolver to apply site-scoped themes. */ export async function resolveSiteDomain(): Promise { const h = await headers(); // Next.js sets host in the Host header const host = h.get("host") ?? h.get("x-forwarded-host"); if (!host) return null; // Strip port if present return host.split(":")[0]; } /** * Build the full theme context from the current request. * Combines site domain + route path + module detection. */ export async function buildThemeContext(pathname: string): Promise<{ siteDomain: string | null; routePath: string; moduleId: string | null; }> { const siteDomain = await resolveSiteDomain(); const { detectModule } = await import("@/lib/theme-modules"); const moduleId = detectModule(pathname); return { siteDomain, routePath: pathname, moduleId, }; }