Skip to content

Commit 6a09fe1

Browse files
authored
templates: fix preview path protocol not being https in production environments (#9910)
1 parent 821bd35 commit 6a09fe1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

templates/website/src/utilities/generatePreviewPath.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export const generatePreviewPath = ({ collection, slug, req }: Props) => {
2626
encodedParams.append(key, value)
2727
})
2828

29-
let url = `${req.protocol}//${req.host}/next/preview?${encodedParams.toString()}`
29+
const isProduction =
30+
process.env.NODE_ENV === 'production' || Boolean(process.env.VERCEL_PROJECT_PRODUCTION_URL)
31+
const protocol = isProduction ? 'https:' : req.protocol
32+
33+
let url = `${protocol}//${req.host}/next/preview?${encodedParams.toString()}`
3034

3135
return url
3236
}

templates/with-vercel-website/src/utilities/generatePreviewPath.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export const generatePreviewPath = ({ collection, slug, req }: Props) => {
2626
encodedParams.append(key, value)
2727
})
2828

29-
let url = `${req.protocol}//${req.host}/next/preview?${encodedParams.toString()}`
29+
const isProduction =
30+
process.env.NODE_ENV === 'production' || Boolean(process.env.VERCEL_PROJECT_PRODUCTION_URL)
31+
const protocol = isProduction ? 'https:' : req.protocol
32+
33+
let url = `${protocol}//${req.host}/next/preview?${encodedParams.toString()}`
3034

3135
return url
3236
}

0 commit comments

Comments
 (0)