environment.js 1.5 KB
Newer Older
J
Jason Park 已提交
1
const path = require('path');
J
Jason Park 已提交
2
const fs = require('fs');
J
Jason Park 已提交
3 4 5 6

const {
  NODE_ENV = 'production',

J
Jason Park 已提交
7 8
  HTTP_PORT = '8080',
  HTTPS_PORT = '8443',
J
Jason Park 已提交
9 10 11

  GITHUB_CLIENT_ID,
  GITHUB_CLIENT_SECRET,
12
  GITHUB_WEBHOOK_SECRET,
J
Jason Park 已提交
13 14 15 16 17 18

  CREDENTIALS_ENABLED = '0',
  CREDENTIALS_PATH,
  CREDENTIALS_CA,
  CREDENTIALS_KEY,
  CREDENTIALS_CERT,
J
Jason Park 已提交
19 20
} = process.env;

J
Jason Park 已提交
21 22
const isEnabled = v => v === '1';

J
Jason Park 已提交
23 24 25
const __PROD__ = NODE_ENV === 'production';
const __DEV__ = !__PROD__;

J
Jason Park 已提交
26 27
const httpPort = parseInt(HTTP_PORT);
const httpsPort = parseInt(HTTPS_PORT);
J
Jason Park 已提交
28

J
Jason Park 已提交
29 30
const githubClientId = GITHUB_CLIENT_ID;
const githubClientSecret = GITHUB_CLIENT_SECRET;
31
const githubWebhookSecret = GITHUB_WEBHOOK_SECRET;
J
Jason Park 已提交
32

J
Jason Park 已提交
33 34 35 36 37 38 39
const read = (file) => fs.readFileSync(path.resolve(CREDENTIALS_PATH, file));
const credentials = isEnabled(CREDENTIALS_ENABLED) && {
  ca: read(CREDENTIALS_CA),
  key: read(CREDENTIALS_KEY),
  cert: read(CREDENTIALS_CERT),
};

J
Jason Park 已提交
40 41 42
const buildPath = path.resolve(__dirname, 'build');
const frontendBuildPath = path.resolve(buildPath, 'frontend');
const backendBuildPath = path.resolve(buildPath, 'backend');
J
Jason Park 已提交
43 44 45 46 47 48 49 50 51 52

const srcPath = path.resolve(__dirname, 'src');
const frontendSrcPath = path.resolve(srcPath, 'frontend');
const backendSrcPath = path.resolve(srcPath, 'backend');

const apiEndpoint = '/api';

module.exports = {
  __PROD__,
  __DEV__,
J
Jason Park 已提交
53 54
  httpPort,
  httpsPort,
J
Jason Park 已提交
55 56
  githubClientId,
  githubClientSecret,
57
  githubWebhookSecret,
J
Jason Park 已提交
58
  credentials,
J
Jason Park 已提交
59 60
  frontendBuildPath,
  backendBuildPath,
J
Jason Park 已提交
61 62 63
  frontendSrcPath,
  backendSrcPath,
  apiEndpoint,
64
};