Skip to content

Instantly share code, notes, and snippets.

@Kcin1993
Created September 28, 2017 08:42
Show Gist options
  • Save Kcin1993/e9be351981ccbdc1aecf16b20988b40f to your computer and use it in GitHub Desktop.
Save Kcin1993/e9be351981ccbdc1aecf16b20988b40f to your computer and use it in GitHub Desktop.
dotEnv-setting.md

Brief

YOSGO Dashboard need use the dotenv package to control deploy.

Flow

1. Create .env file in the root folder

2. Add require dotenv in server.ts

//require
require('dotenv').config()

//add script to html file
<script>
  window.__ENV__ = ${JSON.stringify(pickFromProcessEnv(process.env))}
</script>

3. Create function to pick key from env

//pickFromProcessEnv.ts
import * as R from 'ramda';

const pickFromProcessEnv = R.pick([
  'BASE_API_URL',
]);

export default pickFromProcessEnv;

4. Create get certain env value function

export const BASE_API_URL = window.__ENV__.BASE_API_URL;

5. Use in action

//import file
import { BASE_API_URL } from '../../../getEnv/getEnv';

const BRAND_API_URL = BASE_API_URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment