feat(housekeeping): dispatch canonical domain routes
This commit is contained in:
1 parent
2970dff563
commit
e5c230ba35
13 files changed
+680
-82
No files matched your search
@@ -0,0 +1,43 @@
|
||||
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 });
|
||||
}
|
||||
Reference in new issue
Block a user