From 21d1fa9e48f43b3cd3c0ea2673474d8719474bf2 Mon Sep 17 00:00:00 2001 From: Max Edell Date: Fri, 8 May 2026 10:26:23 -0700 Subject: [PATCH] fix: add x-env header to pdp simulation fetch --- scripts/scripts.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index be07d521..7a271f75 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -1251,7 +1251,18 @@ async function simulatePDPPreview() { const corsProxy = 'https://fcors.org/?url='; const corsKey = '&key=Mg23N96GgR8O3NjU'; const fullUrl = `https://main--vitamix--aemsites.aem.network${url}`; - return fetch(`${corsProxy}${encodeURIComponent(fullUrl)}${corsKey}`); + const { origin } = window.location; + const staging = ( + origin.endsWith('.aem.page') + || origin === 'http://localhost:3000' + || window.location.search.includes('stage=true') + ) && !window.location.search.includes('stage=false'); + + return fetch(`${corsProxy}${encodeURIComponent(fullUrl)}${corsKey}`, { + headers: { + ...(staging ? { 'x-env': 'stage' } : {}), + }, + }); }; const { pathname } = new URL(window.location.href); const resp = await corsProxyFetch(pathname);