fix: make preview env optional

This commit is contained in:
Christel Westerberg
2024-02-07 11:41:13 +01:00
parent 9d05eefd56
commit 93d09c554d
3 changed files with 7 additions and 2 deletions

4
env/schema.mjs vendored
View File

@@ -10,8 +10,8 @@ export const serverSchema = z.object({
CMS_API_KEY: z.string(),
CMS_ENVIRONMENT: z.enum(["development", "production", "staging", "test"]),
CMS_URL: z.string(),
CMS_PREVIEW_URL: z.string(),
CMS_PREVIEW_TOKEN: z.string(),
CMS_PREVIEW_URL: z.string().optional(),
CMS_PREVIEW_TOKEN: z.string().optional(),
NODE_ENV: z.enum(["development", "test", "production"]),
PRINT_QUERY: z.boolean().default(false),
});

View File

@@ -28,6 +28,10 @@ query GetCurrentBlockPage($locale: String!, $url: String!) {
...Preamble
title
url
system {
uid
content_type_uid
}
}
total
}

View File

@@ -37,6 +37,7 @@ export async function middleware(request: NextRequest) {
searchParams.set("uri", pathNameWithoutLocale);
if (request.nextUrl.pathname.includes("preview")) {
console.log("IN PREVIEW! Search params: ", request.nextUrl.searchParams);
if (request.nextUrl.searchParams.get("hash")) {
ContentstackLivePreview.setConfigFromParams(request.nextUrl.searchParams);