44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
import { notFound } from "next/navigation";
|
|
import { satisfiesCapability } from "@/features/housekeeping/foundation/capability-context";
|
|
import { createHousekeepingRegistry } from "@/features/housekeeping/foundation/registry";
|
|
import { matchHousekeepingRoute } from "@/features/housekeeping/foundation/routing/match-route";
|
|
import { getHousekeepingCapabilityContext } from "@/features/housekeeping/foundation/server-capability-context";
|
|
import { HOUSEKEEPING_MANIFESTS } from "@/features/housekeeping/manifests";
|
|
import { HOUSEKEEPING_ROUTE_HANDLERS } from "@/features/housekeeping/route-handlers";
|
|
|
|
export default async function HousekeepingPreviewRoutePage({
|
|
params,
|
|
}: {
|
|
params: Promise<{ domain: string; segments?: readonly string[] }>;
|
|
}) {
|
|
const { domain, segments = [] } = await params;
|
|
const registry = createHousekeepingRegistry(HOUSEKEEPING_MANIFESTS);
|
|
const activeDomain = registry.domains.find((entry) => entry.id === domain);
|
|
if (!activeDomain) notFound();
|
|
|
|
const suffix = segments
|
|
.map((segment) => encodeURIComponent(segment))
|
|
.join("/");
|
|
const canonicalPath = suffix
|
|
? `${activeDomain.canonicalHref}/${suffix}`
|
|
: activeDomain.canonicalHref;
|
|
const match = matchHousekeepingRoute(registry, canonicalPath);
|
|
if (!match || match.domain !== activeDomain.id) notFound();
|
|
|
|
const route = activeDomain.routes.find((entry) => entry.id === match.routeId);
|
|
const handler = HOUSEKEEPING_ROUTE_HANDLERS.find(
|
|
(entry) => entry.routeId === match.routeId,
|
|
);
|
|
if (!route || !handler) notFound();
|
|
|
|
const context = await getHousekeepingCapabilityContext();
|
|
if (
|
|
!satisfiesCapability(context, activeDomain.capability) ||
|
|
!satisfiesCapability(context, route.capability)
|
|
) {
|
|
notFound();
|
|
}
|
|
|
|
return handler.render({ context, match });
|
|
}
|