Skip to content

Commit 66584a2

Browse files
authored
[engage-43-3] fix loading config (bcgov#123)
1 parent e39d664 commit 66584a2

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

met-web/.env.production

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
REACT_APP_KEYCLOAK_CLIENT=met-web
2-
REACT_APP_KEYCLOAK_REALM=met
3-
REACT_APP_KEYCLOAK_URL=https://met-oidc-dev.apps.gold.devops.gov.bc.ca/auth
4-
REACT_APP_API_URL=https://met-web-dev.apps.gold.devops.gov.bc.ca/api
1+
REACT_APP_KEYCLOAK_CLIENT=epic-engage
2+
REACT_APP_KEYCLOAK_REALM=eao-epic
3+
REACT_APP_KEYCLOAK_URL=https://dev.loginproxy.gov.bc.ca/auth
4+
REACT_APP_API_URL=https://epic-engage-web-dev.apps.gold.devops.gov.bc.ca/api

met-web/src/config.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { hasKey } from 'utils';
1+
import { ITenantDetail } from 'constants/types';
2+
23
declare global {
34
interface Window {
45
_env_: {
@@ -30,14 +31,17 @@ declare global {
3031
//tenant
3132
REACT_APP_IS_SINGLE_TENANT_ENVIRONMENT: string;
3233
REACT_APP_DEFAULT_TENANT: string;
34+
35+
[key: string]: string;
3336
};
3437
}
3538
}
3639

37-
const getEnv = (key: string, defaultValue = '') => {
38-
if (hasKey(window._env_, key)) {
40+
export const getEnv = (key: string, defaultValue = ''): string => {
41+
if (typeof window !== 'undefined' && window._env_ && window._env_[key] !== undefined) {
3942
return window._env_[key];
40-
} else return process.env[key] || defaultValue;
43+
}
44+
return process.env[key] || defaultValue;
4145
};
4246

4347
// adding localStorage to access the MET API from external sources(eg: web-components)
@@ -112,3 +116,9 @@ export const AppConfig = {
112116
defaultTenant: DEFAULT_TENANT,
113117
},
114118
};
119+
120+
export const getTenantDetail = (): ITenantDetail => ({
121+
realm: getEnv('REACT_APP_KEYCLOAK_REALM'),
122+
url: getEnv('REACT_APP_KEYCLOAK_URL'),
123+
clientId: getEnv('REACT_APP_KEYCLOAK_CLIENT'),
124+
});
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import { AppConfig } from 'config';
1+
import { getTenantDetail } from 'config';
22
import Keycloak from 'keycloak-js';
3-
import { ITenantDetail } from './types';
43

5-
//TODO get from api
6-
export const tenantDetail: ITenantDetail = {
7-
realm: AppConfig.keycloak.realm,
8-
url: AppConfig.keycloak.url,
9-
clientId: AppConfig.keycloak.clientId,
10-
};
11-
12-
export const _kc = new Keycloak(tenantDetail);
4+
export const _kc = new Keycloak(getTenantDetail());

0 commit comments

Comments
 (0)