Merged in fix/preview-contentstack (pull request #1380)
* fix: preview in contentstack now works again Approved-by: Joakim Jäderberg
This commit is contained in:
committed by
Joakim Jäderberg
parent
e75c714148
commit
21e564934d
@@ -18,17 +18,13 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
|
||||
const pathWithoutTrailingSlash = removeTrailingSlash(nextUrl.pathname)
|
||||
|
||||
const contentTypePathName = pathWithoutTrailingSlash.replace(`/${lang}`, "")
|
||||
|
||||
const isPreview = request.nextUrl.pathname.includes("/preview")
|
||||
|
||||
const incomingPathName = isPreview
|
||||
? contentTypePathName.replace("/preview", "")
|
||||
: contentTypePathName
|
||||
? pathWithoutTrailingSlash.replace("/preview", "")
|
||||
: pathWithoutTrailingSlash
|
||||
|
||||
let { contentType, uid } = await getUidAndContentTypeByPath(
|
||||
pathWithoutTrailingSlash
|
||||
)
|
||||
let { contentType, uid } = await getUidAndContentTypeByPath(incomingPathName)
|
||||
|
||||
const searchParams = new URLSearchParams(request.nextUrl.searchParams)
|
||||
|
||||
@@ -62,7 +58,7 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
|
||||
if (!contentType || !uid) {
|
||||
throw notFound(
|
||||
`Unable to resolve CMS entry for locale "${lang}": ${contentTypePathName}`
|
||||
`Unable to resolve CMS entry for page "${pathWithoutTrailingSlash}"`
|
||||
)
|
||||
}
|
||||
const headers = getDefaultRequestHeaders(request)
|
||||
@@ -87,6 +83,7 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
}
|
||||
|
||||
if (isCurrent) {
|
||||
const contentTypePathName = pathWithoutTrailingSlash.replace(`/${lang}`, "")
|
||||
searchParams.set("uid", uid)
|
||||
searchParams.set("uri", contentTypePathName)
|
||||
return NextResponse.rewrite(
|
||||
|
||||
Reference in New Issue
Block a user