fix(SW-663): Fixed leaking of live preview hash and removing preview pages

This commit is contained in:
Erik Tiekstra
2024-11-07 12:49:13 +01:00
parent 0465f8e450
commit 953f860e5d
16 changed files with 117 additions and 301 deletions

View File

@@ -19,7 +19,6 @@ export const middleware: NextMiddleware = async (request) => {
const contentTypePathName = pathWithoutTrailingSlash.replace(`/${lang}`, "")
const isPreview = request.nextUrl.pathname.includes("/preview")
const searchParams = new URLSearchParams(request.nextUrl.searchParams)
const { contentType, uid } = await fetchAndCacheEntry(
@@ -41,21 +40,10 @@ export const middleware: NextMiddleware = async (request) => {
const isCurrent = contentType ? contentType.indexOf("current") >= 0 : false
if (isPreview) {
if (isCurrent) {
searchParams.set("uri", contentTypePathName.replace("/preview", ""))
return NextResponse.rewrite(
new URL(`/${lang}/preview-current?${searchParams.toString()}`, nextUrl),
{
request: {
headers,
},
}
)
}
searchParams.set("isPreview", "true")
return NextResponse.rewrite(
new URL(
`/${lang}/preview/${contentType}/${uid}?${searchParams.toString()}`,
`/${lang}/${contentType}/${uid}?${searchParams.toString()}`,
nextUrl
),
{