UNPKG

903 BJavaScriptView Raw
1/**
2 * init dotenv
3 *
4 * .env: Default.
5 * .env.local: Local overrides. This file is loaded for all environments except test.
6 * .env.development, .env.test, .env.production: Environment-specific settings.
7 * .env.development.local, .env.test.local, .env.production.local: Local overrides of environment-specific settings.
8 *
9 * Available settings
10 *
11 * APP_PORT=9527
12 * APP_BASE_PATH=/v1
13 * APP_JWT_PUBLIC_KEY=`a public key string`
14 */
15
16/**
17 *
18 * @param {string} name envrionment name
19 * @param {object} opt option with { required, default }
20 * @returns {*} value
21 */
22
23export function env(name, init) {
24 const value = process.env[`REACT_APP_${name.toUpperCase()}`] || init;
25
26 if (value === undefined) {
27 throw new Error(`environment ${name} is missing`);
28 }
29
30 return value;
31}
32
33/**
34 * APP
35 */
36export const STORE_BASE = env("STORE_BASE", "");
37export const TOKEN = env("TOKEN", "some fake token");