Skip to content

Env fixes #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
391 changes: 194 additions & 197 deletions .circleci/config.yml

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions .environments/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ REACT_APP_ENABLE_TCA_CERT_MONETIZATION=false
# Stripe configs
REACT_APP_STRIPE_API_KEY=pk_test_rfcS49MHRVUKomQ9JgSH7Xqz
REACT_APP_STRIPE_API_VERSION=2020-08-27
# not really used anywhere
REACT_APP_STRIPE_ADMIN_TOKEN=
REACT_APP_STRIPE_CUSTOMER_TOKEN=

# Vanilla Forums
REACT_APP_VANILLA_ACCESS_TOKEN=va.JApNvUOx3549h20I6tnl1kOQDc75NDIp.0jG3dA.EE3gZgV
Expand Down
3 changes: 0 additions & 3 deletions .environments/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ REACT_APP_ENABLE_TCA_CERT_MONETIZATION=false
# Stripe configs
REACT_APP_STRIPE_API_KEY=pk_live_m3bCBVSfkfMOEp3unZFRsHXi
REACT_APP_STRIPE_API_VERSION=2020-08-27
# not really used anywhere
REACT_APP_STRIPE_ADMIN_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIiwiYWRtaW5pc3RyYXRvciJdLCJpc3MiOiJodHRwczovL2FwaS50b3Bjb2Rlci1kZXYuY29tIiwiaGFuZGxlIjoidGVzdDEiLCJleHAiOjI1NjMwNzY2ODksInVzZXJJZCI6IjQwMDUxMzMzIiwiaWF0IjoxNDYzMDc2MDg5LCJlbWFpbCI6InRlc3RAdG9wY29kZXIuY29tIiwianRpIjoiYjMzYjc3Y2QtYjUyZS00MGZlLTgzN2UtYmViOGUwYWU2YTRhIn0.wKWUe0-SaiFVN-VR_-GwgFlvWaDkSbc8H55ktb9LAVw
REACT_APP_STRIPE_CUSTOMER_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJ0ZXN0MSIsImV4cCI6MjU2MzA3NjY4OSwidXNlcklkIjoiNDAwNTEzMzMiLCJpYXQiOjE0NjMwNzYwODksImVtYWlsIjoidGVzdEB0b3Bjb2Rlci5jb20iLCJqdGkiOiJiMzNiNzdjZC1iNTJlLTQwZmUtODM3ZS1iZWI4ZTBhZTZhNGEifQ.jl6Lp_friVNwEP8nfsfmL-vrQFzOFp2IfM_HC7AwGcg

# Vanilla Forums
REACT_APP_VANILLA_ACCESS_TOKEN=va.JApNvUOx3549h20I6tnl1kOQDc75NDIp.0jG3dA.EE3gZgV
Expand Down
3 changes: 0 additions & 3 deletions .environments/.env.qa
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ REACT_APP_ENABLE_TCA_CERT_MONETIZATION=false
# Stripe configs
REACT_APP_STRIPE_API_KEY=pk_test_rfcS49MHRVUKomQ9JgSH7Xqz
REACT_APP_STRIPE_API_VERSION=2020-08-27
# not really used anywhere
REACT_APP_STRIPE_ADMIN_TOKEN=
REACT_APP_STRIPE_CUSTOMER_TOKEN=

# Vanilla Forums
REACT_APP_VANILLA_ACCESS_TOKEN=va.JApNvUOx3549h20I6tnl1kOQDc75NDIp.0jG3dA.EE3gZgV
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"private": true,
"license": "ISC",
"scripts": {
"dev": "craco start --mode ${REACT_APP_HOST_ENV:-dev}",
"dev": "craco start --mode ${LOGICAL_ENV:-dev}",
"start": "bash start.sh",
"build": "export CI=false && craco build --mode ${REACT_APP_HOST_ENV:-prod}",
"build:dev": "craco build --mode ${REACT_APP_HOST_ENV:-dev}",
"build": "export CI=false && craco build --mode ${LOGICAL_ENV:-prod}",
"build:dev": "craco build --mode ${LOGICAL_ENV:-dev}",
"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",
"lint": "eslint -c ./src/.eslintrc.js 'src/**/*.{ts,tsx,js,jsx}'",
"lint:fix": "yarn lint --fix",
Expand Down
2 changes: 0 additions & 2 deletions src/config/environments/default.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ export const VANILLA_FORUM = {
}

export const STRIPE = {
ADMIN_TOKEN: getReactEnv<string | undefined>('STRIPE_ADMIN_TOKEN', undefined),
API_KEY: getReactEnv<string>('STRIPE_API_KEY', ''),
API_VERSION: getReactEnv<string | undefined>('STRIPE_API_VERSION', undefined),
CUSTOMER_TOKEN: getReactEnv<string | undefined>('STRIPE_CUSTOMER_TOKEN', undefined),
}

export const URLS = {
Expand Down
2 changes: 0 additions & 2 deletions src/config/environments/global-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ export interface GlobalConfig {
ENVIRONMENT_ID: string | undefined
}
STRIPE: {
ADMIN_TOKEN: string | undefined
API_KEY: string
API_VERSION: string | undefined
CUSTOMER_TOKEN: string | undefined
}
URLS: {
USER_PROFILE: string
Expand Down
18 changes: 17 additions & 1 deletion src/config/environments/react-env.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
/* eslint-disable unicorn/no-null */
/* eslint-disable @typescript-eslint/typedef */

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

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

// convert to boolean
if (value === 'false' || value === 'true') {
value = (value === 'true' as unknown) as T
}

// convert to null
if (value === 'null') {
value = (null as unknown) as T
}

// convert to number
if (!Number.isNaN(Number(value))) {
value = (null as unknown) as T
}

return (value ?? defaultValue) as T
}