- Improve handle beta code (AIO Version)
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -20,22 +20,27 @@ export const handleBeta = () => {
|
|||||||
const currentHostName = window.location.hostname;
|
const currentHostName = window.location.hostname;
|
||||||
|
|
||||||
// Determine if the host name starts with "beta" or "www.beta"
|
// Determine if the host name starts with "beta" or "www.beta"
|
||||||
const isBetaHost = currentHostName.startsWith("beta");
|
const isBetaHost = currentHostName.startsWith("beta.");
|
||||||
const isBetaHostWithWWW = currentHostName.startsWith("www.beta");
|
const isBetaHostWithWWW = currentHostName.startsWith("www.beta.");
|
||||||
|
|
||||||
// Handle beta redirection
|
if (isBeta) {
|
||||||
if (isBeta && !isBetaHost && !isBetaHostWithWWW) {
|
// If beta is on and we are not on a beta domain, redirect to the beta version
|
||||||
// From non-beta to beta
|
if (!isBetaHost && !isBetaHostWithWWW) {
|
||||||
const newHostName = currentHostName.startsWith("www.")
|
const newHostName = currentHostName.startsWith("www.")
|
||||||
? `www.beta.${currentHostName.replace(/^www\./, "")}`
|
? `www.beta.${currentHostName.replace(/^www\./, "")}`
|
||||||
: `beta.${currentHostName}`;
|
: `beta.${currentHostName}`;
|
||||||
const href = `${window.location.protocol}//${newHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
const href = `${window.location.protocol}//${newHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
||||||
window.location.replace(href);
|
window.location.replace(href);
|
||||||
} else if (!isBeta && (isBetaHost || isBetaHostWithWWW)) {
|
}
|
||||||
// From beta to non-beta
|
// Otherwise, if beta is on and we're already on a beta domain, stay there
|
||||||
const newHostName = currentHostName.replace(/^www\./, "").replace(/^beta\./, "www.");
|
} else {
|
||||||
const href = `${window.location.protocol}//${newHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
// If beta is off and we are on a beta domain, redirect to the non-beta version
|
||||||
window.location.replace(href);
|
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
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user