From 6a09fe1bf92f986c63cd4cd44e06c250c93b1711 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 11 Dec 2024 14:52:07 -0600 Subject: [PATCH] templates: fix preview path protocol not being https in production environments (#9910) --- templates/website/src/utilities/generatePreviewPath.ts | 6 +++++- .../src/utilities/generatePreviewPath.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/templates/website/src/utilities/generatePreviewPath.ts b/templates/website/src/utilities/generatePreviewPath.ts index 5179f6889ab..56a9e0ec4f2 100644 --- a/templates/website/src/utilities/generatePreviewPath.ts +++ b/templates/website/src/utilities/generatePreviewPath.ts @@ -26,7 +26,11 @@ export const generatePreviewPath = ({ collection, slug, req }: Props) => { encodedParams.append(key, value) }) - let url = `${req.protocol}//${req.host}/next/preview?${encodedParams.toString()}` + const isProduction = + process.env.NODE_ENV === 'production' || Boolean(process.env.VERCEL_PROJECT_PRODUCTION_URL) + const protocol = isProduction ? 'https:' : req.protocol + + let url = `${protocol}//${req.host}/next/preview?${encodedParams.toString()}` return url } diff --git a/templates/with-vercel-website/src/utilities/generatePreviewPath.ts b/templates/with-vercel-website/src/utilities/generatePreviewPath.ts index 5179f6889ab..56a9e0ec4f2 100644 --- a/templates/with-vercel-website/src/utilities/generatePreviewPath.ts +++ b/templates/with-vercel-website/src/utilities/generatePreviewPath.ts @@ -26,7 +26,11 @@ export const generatePreviewPath = ({ collection, slug, req }: Props) => { encodedParams.append(key, value) }) - let url = `${req.protocol}//${req.host}/next/preview?${encodedParams.toString()}` + const isProduction = + process.env.NODE_ENV === 'production' || Boolean(process.env.VERCEL_PROJECT_PRODUCTION_URL) + const protocol = isProduction ? 'https:' : req.protocol + + let url = `${protocol}//${req.host}/next/preview?${encodedParams.toString()}` return url }