Skip to content

Commit 7f981b4

Browse files
authored
Merge pull request #749 from topcoder-platform/env-fixes
Env fixes
2 parents 5b285f4 + 35d7690 commit 7f981b4

File tree

8 files changed

+214
-214
lines changed

8 files changed

+214
-214
lines changed

.circleci/config.yml

Lines changed: 194 additions & 197 deletions
Large diffs are not rendered by default.

.environments/.env.dev

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ REACT_APP_ENABLE_TCA_CERT_MONETIZATION=false
55
# Stripe configs
66
REACT_APP_STRIPE_API_KEY=pk_test_rfcS49MHRVUKomQ9JgSH7Xqz
77
REACT_APP_STRIPE_API_VERSION=2020-08-27
8-
# not really used anywhere
9-
REACT_APP_STRIPE_ADMIN_TOKEN=
10-
REACT_APP_STRIPE_CUSTOMER_TOKEN=
118

129
# Vanilla Forums
1310
REACT_APP_VANILLA_ACCESS_TOKEN=va.JApNvUOx3549h20I6tnl1kOQDc75NDIp.0jG3dA.EE3gZgV

.environments/.env.prod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ REACT_APP_ENABLE_TCA_CERT_MONETIZATION=false
55
# Stripe configs
66
REACT_APP_STRIPE_API_KEY=pk_live_m3bCBVSfkfMOEp3unZFRsHXi
77
REACT_APP_STRIPE_API_VERSION=2020-08-27
8-
# not really used anywhere
9-
REACT_APP_STRIPE_ADMIN_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw
10-
REACT_APP_STRIPE_CUSTOMER_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJ0ZXN0MSIsImV4cCI6MjU2MzA3NjY4OSwidXNlcklkIjoiNDAwNTEzMzMiLCJpYXQiOjE0NjMwNzYwODksImVtYWlsIjoidGVzdEB0b3Bjb2Rlci5jb20iLCJqdGkiOiJiMzNiNzdjZC1iNTJlLTQwZmUtODM3ZS1iZWI4ZTBhZTZhNGEifQ.jl6Lp_friVNwEP8nfsfmL-vrQFzOFp2IfM_HC7AwGcg
118

129
# Vanilla Forums
1310
REACT_APP_VANILLA_ACCESS_TOKEN=va.JApNvUOx3549h20I6tnl1kOQDc75NDIp.0jG3dA.EE3gZgV

.environments/.env.qa

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ REACT_APP_ENABLE_TCA_CERT_MONETIZATION=false
55
# Stripe configs
66
REACT_APP_STRIPE_API_KEY=pk_test_rfcS49MHRVUKomQ9JgSH7Xqz
77
REACT_APP_STRIPE_API_VERSION=2020-08-27
8-
# not really used anywhere
9-
REACT_APP_STRIPE_ADMIN_TOKEN=
10-
REACT_APP_STRIPE_CUSTOMER_TOKEN=
118

129
# Vanilla Forums
1310
REACT_APP_VANILLA_ACCESS_TOKEN=va.JApNvUOx3549h20I6tnl1kOQDc75NDIp.0jG3dA.EE3gZgV

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"private": true,
55
"license": "ISC",
66
"scripts": {
7-
"dev": "craco start --mode ${REACT_APP_HOST_ENV:-dev}",
7+
"dev": "craco start --mode ${LOGICAL_ENV:-dev}",
88
"start": "bash start.sh",
9-
"build": "export CI=false && craco build --mode ${REACT_APP_HOST_ENV:-prod}",
10-
"build:dev": "craco build --mode ${REACT_APP_HOST_ENV:-dev}",
9+
"build": "export CI=false && craco build --mode ${LOGICAL_ENV:-prod}",
10+
"build:dev": "craco build --mode ${LOGICAL_ENV:-dev}",
1111
"demo": "npx http-server --port 443 -a 0.0.0.0 -S -C ./ssl/rootCA.crt -K ./ssl/rootCA.key -P https://local.topcoder-dev.com? --proxy-options.secure false ./build",
1212
"lint": "eslint -c ./src/.eslintrc.js 'src/**/*.{ts,tsx,js,jsx}'",
1313
"lint:fix": "yarn lint --fix",

src/config/environments/default.env.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ export const VANILLA_FORUM = {
4242
}
4343

4444
export const STRIPE = {
45-
ADMIN_TOKEN: getReactEnv<string | undefined>('STRIPE_ADMIN_TOKEN', undefined),
4645
API_KEY: getReactEnv<string>('STRIPE_API_KEY', ''),
4746
API_VERSION: getReactEnv<string | undefined>('STRIPE_API_VERSION', undefined),
48-
CUSTOMER_TOKEN: getReactEnv<string | undefined>('STRIPE_CUSTOMER_TOKEN', undefined),
4947
}
5048

5149
export const URLS = {

src/config/environments/global-config.model.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ export interface GlobalConfig {
2222
ENVIRONMENT_ID: string | undefined
2323
}
2424
STRIPE: {
25-
ADMIN_TOKEN: string | undefined
2625
API_KEY: string
2726
API_VERSION: string | undefined
28-
CUSTOMER_TOKEN: string | undefined
2927
}
3028
URLS: {
3129
USER_PROFILE: string

src/config/environments/react-env.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
/* eslint-disable unicorn/no-null */
12
/* eslint-disable @typescript-eslint/typedef */
23

34
export function getReactEnv<T>(varName: string, defaultValue?: string | boolean | number): T {
45
const hasDefaultValue: boolean = arguments.length > 1
5-
const value = process.env[`REACT_APP_${varName}`]
6+
let value = process.env[`REACT_APP_${varName}`] as unknown as T
67

78
if (value === undefined && !hasDefaultValue) {
89
throw new Error(`${varName} is not defined in process.env!`)
910
}
1011

12+
// convert to boolean
13+
if (value === 'false' || value === 'true') {
14+
value = (value === 'true' as unknown) as T
15+
}
16+
17+
// convert to null
18+
if (value === 'null') {
19+
value = (null as unknown) as T
20+
}
21+
22+
// convert to number
23+
if (!Number.isNaN(Number(value))) {
24+
value = (null as unknown) as T
25+
}
26+
1127
return (value ?? defaultValue) as T
1228
}

0 commit comments

Comments
 (0)