Merged in fix/hotel-subpage-unable-to-fetch (pull request #1381)

fix: was unable to fetch hotel subpage data, now uses the same function as when fetching a 'normal' hotel page

* fix: was unable to fetch hotel subpage data, now uses the same function as when fetching a 'normal' hotel page


Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-02-20 10:05:26 +00:00
committed by Linus Flood
parent 7155165360
commit 00b94976b7

View File

@@ -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
}