From 5a36cb7cf1df4d5c7d8bb6badd85742281946248 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Thu, 15 Aug 2024 11:19:59 -0400 Subject: [PATCH] - Improve handle beta code (AIO Version) Signed-off-by: Dave Richer --- client/src/utils/handleBeta.js | 35 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/client/src/utils/handleBeta.js b/client/src/utils/handleBeta.js index 34bdab626..dcb0d18d1 100644 --- a/client/src/utils/handleBeta.js +++ b/client/src/utils/handleBeta.js @@ -20,22 +20,27 @@ export const handleBeta = () => { const currentHostName = window.location.hostname; // Determine if the host name starts with "beta" or "www.beta" - const isBetaHost = currentHostName.startsWith("beta"); - const isBetaHostWithWWW = currentHostName.startsWith("www.beta"); + const isBetaHost = currentHostName.startsWith("beta."); + const isBetaHostWithWWW = currentHostName.startsWith("www.beta."); - // Handle beta redirection - if (isBeta && !isBetaHost && !isBetaHostWithWWW) { - // From non-beta to beta - const newHostName = currentHostName.startsWith("www.") - ? `www.beta.${currentHostName.replace(/^www\./, "")}` - : `beta.${currentHostName}`; - const href = `${window.location.protocol}//${newHostName}${window.location.pathname}${window.location.search}${window.location.hash}`; - window.location.replace(href); - } else if (!isBeta && (isBetaHost || isBetaHostWithWWW)) { - // From beta to non-beta - const newHostName = currentHostName.replace(/^www\./, "").replace(/^beta\./, "www."); - const href = `${window.location.protocol}//${newHostName}${window.location.pathname}${window.location.search}${window.location.hash}`; - window.location.replace(href); + if (isBeta) { + // If beta is on and we are not on a beta domain, redirect to the beta version + if (!isBetaHost && !isBetaHostWithWWW) { + const newHostName = currentHostName.startsWith("www.") + ? `www.beta.${currentHostName.replace(/^www\./, "")}` + : `beta.${currentHostName}`; + const href = `${window.location.protocol}//${newHostName}${window.location.pathname}${window.location.search}${window.location.hash}`; + window.location.replace(href); + } + // Otherwise, if beta is on and we're already on a beta domain, stay there + } else { + // If beta is off and we are on a beta domain, redirect to the non-beta version + if (isBetaHost || isBetaHostWithWWW) { + const newHostName = currentHostName.replace(/^www\.beta\./, "www.").replace(/^beta\./, ""); + const href = `${window.location.protocol}//${newHostName}${window.location.pathname}${window.location.search}${window.location.hash}`; + window.location.replace(href); + } + // Otherwise, if beta is off and we're not on a beta domain, stay there } };