diff --git a/middlewares/cmsContent.ts b/middlewares/cmsContent.ts index 5f5409e0c..f525c5d98 100644 --- a/middlewares/cmsContent.ts +++ b/middlewares/cmsContent.ts @@ -2,7 +2,6 @@ import { type NextMiddleware, NextResponse } from "next/server" import { notFound } from "@/server/errors/next" -import { fetchAndCacheEntry } from "@/services/cms/fetchAndCacheEntry" import { getUidAndContentTypeByPath } from "@/services/cms/getUidAndContentTypeByPath" import { findLang } from "@/utils/languages" import { removeTrailingSlash } from "@/utils/url" @@ -37,17 +36,15 @@ export const middleware: NextMiddleware = async (request) => { if (incomingPathNameParts.length >= 2) { const subpage = incomingPathNameParts.pop() if (subpage) { - const parentPageResult = await fetchAndCacheEntry( - incomingPathNameParts.join("/"), - lang - ) + let { contentType: parentContentType, uid: parentUid } = + await getUidAndContentTypeByPath(incomingPathNameParts.join("/")) - if (parentPageResult.uid) { - switch (parentPageResult.contentType) { + if (parentUid) { + switch (parentContentType) { case PageContentTypeEnum.hotelPage: // E.g. Dedicated pages for restaurant, parking etc. - contentType = parentPageResult.contentType - uid = parentPageResult.uid + contentType = parentContentType + uid = parentUid searchParams.set("subpage", subpage) break }