Merged in feat/refactor-header-footer-sitewidealert (pull request #1374)
Refactor: removed parallel routes for header, footer and sidewidealert. Langswitcher and sidewidealert now client components * feat - removed parallel routes and made sidepeek and sitewidealerts as client components * Langswitcher as client component * Fixed lang switcher for current header * Passing lang when fetching siteconfig * Merge branch 'master' into feat/refactor-header-footer-sitewidealert * Refactor * Removed dead code * Show only languages that has translation * Refetch sitewidealert every 60 seconds * Merge branch 'master' into feat/refactor-header-footer-sitewidealert * Removed sidepeek parallel route from my-stay * Added missing env.var to env.test * Removed console.log Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -2,10 +2,12 @@ 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"
|
||||
|
||||
import { fetchAndCacheEntry, getDefaultRequestHeaders } from "./utils"
|
||||
import { getDefaultRequestHeaders } from "./utils"
|
||||
|
||||
import type { MiddlewareMatcher } from "@/types/middleware"
|
||||
import { PageContentTypeEnum } from "@/types/requests/contentType"
|
||||
@@ -17,22 +19,21 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
const pathWithoutTrailingSlash = removeTrailingSlash(nextUrl.pathname)
|
||||
|
||||
const contentTypePathName = pathWithoutTrailingSlash.replace(`/${lang}`, "")
|
||||
const isPreview = request.nextUrl.pathname.includes("/preview")
|
||||
const searchParams = new URLSearchParams(request.nextUrl.searchParams)
|
||||
|
||||
let { contentType, uid } = await fetchAndCacheEntry(
|
||||
isPreview
|
||||
? contentTypePathName.replace("/preview", "")
|
||||
: contentTypePathName,
|
||||
lang
|
||||
)
|
||||
const isPreview = request.nextUrl.pathname.includes("/preview")
|
||||
|
||||
const incomingPathName = isPreview
|
||||
? contentTypePathName.replace("/preview", "")
|
||||
: contentTypePathName
|
||||
|
||||
let { contentType, uid } = await getUidAndContentTypeByPath(incomingPathName)
|
||||
|
||||
const searchParams = new URLSearchParams(request.nextUrl.searchParams)
|
||||
|
||||
if (!contentType || !uid) {
|
||||
// Routes to subpages we need to check if the parent of the incomingPathName exists.
|
||||
// Then we considered the incomingPathName to be a subpage. These subpages do not live in the CMS.
|
||||
const incomingPathName = isPreview
|
||||
? contentTypePathName.replace("/preview", "")
|
||||
: contentTypePathName
|
||||
|
||||
const incomingPathNameParts = incomingPathName.split("/")
|
||||
|
||||
// If the incomingPathName has 2 or more parts, it could possibly be a subpage.
|
||||
|
||||
Reference in New Issue
Block a user