({
hostname,
isBrowser,
defaultStack = buildConstants.defaultStack,
}: {
hostname: string;
isBrowser: boolean;
defaultStack?: string;
})
| 39 | * kind - Local cloud stack running in kind |
| 40 | */ |
| 41 | export const getCurrentStack = ({ |
| 42 | hostname, |
| 43 | isBrowser, |
| 44 | defaultStack = buildConstants.defaultStack, |
| 45 | }: { |
| 46 | hostname: string; |
| 47 | isBrowser: boolean; |
| 48 | defaultStack?: string; |
| 49 | }) => { |
| 50 | if (!isBrowser) return getE2eTestStack(hostname); |
| 51 | |
| 52 | if (buildConstants.forceOverrideStack) { |
| 53 | return buildConstants.forceOverrideStack; |
| 54 | } |
| 55 | if (storageAvailable("localStorage")) { |
| 56 | const stack = window.localStorage.getItem(CURRENT_STACK_KEY); |
| 57 | if (stack) { |
| 58 | return stack; |
| 59 | } |
| 60 | } |
| 61 | if ( |
| 62 | hostname.startsWith("staging.") || |
| 63 | hostname.startsWith("oidc-test.") || |
| 64 | hostname.startsWith("local.console") || |
| 65 | hostname.match(/^.*\.preview/) |
| 66 | ) { |
| 67 | // matches staging.console.materialize.com |
| 68 | // or oid-test.console.materialize.com |
| 69 | // or local.console.materialize.com |
| 70 | // or *.preview.console.materialize.com |
| 71 | return "staging"; |
| 72 | } |
| 73 | if (hostname.startsWith("loadtest.")) { |
| 74 | return "loadtest"; |
| 75 | } |
| 76 | if (hostname.startsWith("local.dev.")) { |
| 77 | return defaultStack; |
| 78 | } |
| 79 | const personalStackMatch = hostname.match(/^\w*\.(staging|dev)/); |
| 80 | if (personalStackMatch) { |
| 81 | // personal stack, return $USER.$ENV |
| 82 | return personalStackMatch[0]; |
| 83 | } |
| 84 | return defaultStack; |
| 85 | }; |
| 86 | |
| 87 | export const setCurrentStack = (stackName: string) => { |
| 88 | if (storageAvailable("localStorage")) { |
no test coverage detected