- Improve handle beta code (AIO Version)
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -18,7 +18,7 @@ import { checkUserSession } from "../redux/user/user.actions";
|
|||||||
import { selectBodyshop, selectCurrentEula, selectCurrentUser } from "../redux/user/user.selectors";
|
import { selectBodyshop, selectCurrentEula, selectCurrentUser } from "../redux/user/user.selectors";
|
||||||
import PrivateRoute from "../components/PrivateRoute";
|
import PrivateRoute from "../components/PrivateRoute";
|
||||||
import "./App.styles.scss";
|
import "./App.styles.scss";
|
||||||
import handleBeta from "../utils/betaHandler";
|
import handleBeta from "../utils/handleBeta";
|
||||||
import Eula from "../components/eula/eula.component";
|
import Eula from "../components/eula/eula.component";
|
||||||
import InstanceRenderMgr from "../utils/instanceRenderMgr";
|
import InstanceRenderMgr from "../utils/instanceRenderMgr";
|
||||||
import ProductFruitsWrapper from "./ProductFruitsWrapper.jsx";
|
import ProductFruitsWrapper from "./ProductFruitsWrapper.jsx";
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import { selectRecentItems, selectSelectedHeader } from "../../redux/application
|
|||||||
import { setModalContext } from "../../redux/modals/modals.actions";
|
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||||
import { signOutStart } from "../../redux/user/user.actions";
|
import { signOutStart } from "../../redux/user/user.actions";
|
||||||
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
||||||
import { checkBeta, handleBeta, setBeta } from "../../utils/betaHandler";
|
import { checkBeta, handleBeta, setBeta } from "../../utils/handleBeta";
|
||||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||||
import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component";
|
import { HasFeatureAccess } from "../feature-wrapper/feature-wrapper.component";
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
export const BETA_KEY = "betaSwitchImex";
|
|
||||||
|
|
||||||
export const checkBeta = () => {
|
|
||||||
const cookie = document.cookie.split("; ").find((row) => row.startsWith(BETA_KEY));
|
|
||||||
return cookie ? cookie.split("=")[1] === "true" : false;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const setBeta = (value) => {
|
|
||||||
const domain = window.location.hostname.split(".").slice(-2).join(".");
|
|
||||||
document.cookie = `${BETA_KEY}=${value}; path=/; domain=.${domain}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const handleBeta = () => {
|
|
||||||
// If the current host name does not start with beta or test, then we don't need to do anything.
|
|
||||||
if (window.location.hostname.startsWith("localhost")) {
|
|
||||||
console.log("Not on beta or test, so no need to handle beta.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isBeta = checkBeta();
|
|
||||||
|
|
||||||
const currentHostName = window.location.hostname;
|
|
||||||
|
|
||||||
// Beta is enabled, but the current host name does start with beta.
|
|
||||||
if (isBeta && !currentHostName.startsWith("beta")) {
|
|
||||||
const href = `${window.location.protocol}//beta.${currentHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
||||||
window.location.replace(href);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Beta is not enabled, but the current host name does start with beta.
|
|
||||||
else if (!isBeta && currentHostName.startsWith("beta")) {
|
|
||||||
const href = `${window.location.protocol}//${currentHostName.replace("beta.", "")}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
||||||
window.location.replace(href);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
export default handleBeta;
|
|
||||||
@@ -11,26 +11,32 @@ export const setBeta = (value) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const handleBeta = () => {
|
export const handleBeta = () => {
|
||||||
// If the current host name does not start with beta or test, then we don't need to do anything.
|
|
||||||
if (window.location.hostname.startsWith("localhost")) {
|
if (window.location.hostname.startsWith("localhost")) {
|
||||||
console.log("Not on beta or test, so no need to handle beta.");
|
console.log("Not on beta or test, so no need to handle beta.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isBeta = checkBeta();
|
const isBeta = checkBeta();
|
||||||
|
|
||||||
const currentHostName = window.location.hostname;
|
const currentHostName = window.location.hostname;
|
||||||
|
|
||||||
// Beta is enabled, but the current host name does start with beta.
|
// Determine if the host name starts with "beta" or "www.beta"
|
||||||
if (isBeta && !currentHostName.startsWith("beta")) {
|
const isBetaHost = currentHostName.startsWith("beta");
|
||||||
const href = `${window.location.protocol}//beta.${currentHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
const isBetaHostWithWWW = currentHostName.startsWith("www.beta");
|
||||||
window.location.replace(href);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Beta is not enabled, but the current host name does start with beta.
|
// Handle beta redirection
|
||||||
else if (!isBeta && currentHostName.startsWith("beta")) {
|
if (isBeta && !isBetaHost && !isBetaHostWithWWW) {
|
||||||
const href = `${window.location.protocol}//${currentHostName.replace("beta.", "")}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
// 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);
|
window.location.replace(href);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default handleBeta;
|
export default handleBeta;
|
||||||
|
|||||||
Reference in New Issue
Block a user