- Add in the Beta Switch on test
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
37
client/src/utils/handleBeta.js
Normal file
37
client/src/utils/handleBeta.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import React, {useState} from "react";
|
||||
|
||||
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')) {
|
||||
window.location.href = `${window.location.protocol}//beta.${currentHostName}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
||||
}
|
||||
|
||||
// Beta is not enabled, but the current host name does start with beta.
|
||||
else if (!isBeta && currentHostName.startsWith('beta')) {
|
||||
window.location.href = `${window.location.protocol}//${currentHostName.replace('beta.', '')}${window.location.pathname}${window.location.search}${window.location.hash}`;
|
||||
}
|
||||
}
|
||||
export default handleBeta;
|
||||
Reference in New Issue
Block a user