-
Notifications
You must be signed in to change notification settings - Fork 48
/
config.js
221 lines (206 loc) · 6.96 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/**
* Copyright (c) 2016, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/
/**
* ./config.js
*
* Configuration Settings
*/
'use strict'; // eslint-disable-line strict
require('./config/toggles'); // Loads the feature toggles
const configUtil = require('./config/configUtil');
const defaultPort = 3000;
const defaultPostgresPort = 5432;
const pe = process.env; // eslint-disable-line no-process-env
const nodeEnv = pe.NODE_ENV || 'development';
const port = pe.PORT || defaultPort;
const defaultPayloadLimit = '200MB';
const payloadLimit = pe.REQUEST_PAYLOAD_LIMIT || defaultPayloadLimit;
const pgdatabase = pe.PGDATABASE || 'focusdb';
const pguser = pe.PGUSER || 'postgres';
const pgpass = pe.PGPASS || 'postgres';
const pghost = pe.PGHOST || 'localhost';
const pgport = pe.PGPORT || defaultPostgresPort;
const defaultDbUrl = 'postgres://' + pguser + ':' + pgpass + '@' + pghost +
':' + pgport + '/' + pgdatabase;
const DEFAULT_LOCAL_REDIS_URL = '//127.0.0.1:6379';
// By default, allow all IP's
const ipWhitelist = pe.IP_WHITELIST || '[[0.0.0.0,255.255.255.255]]';
const iplist = configUtil.parseIPlist(ipWhitelist);
// Check for timed-out samples every 30 seconds if not specified in env var
const DEFAULT_CHECK_TIMEOUT_INTERVAL_MILLIS = 30000;
// Expiry time used for redis cache
const CACHE_EXPIRY_IN_SECS = 60;
// request limiter settings
const rateLimit = pe.DDOS_RATE_LIMIT;
const rateWindow = pe.DDOS_RATE_WINDOW;
const endpointToLimit = pe.DDOS_ENDPOINT_TO_LIMIT;
const httpMethodToLimit = pe.DDOS_HTTP_METHOD_TO_LIMIT;
const DEFAULT_PERSIST_REDIS_SAMPLE_STORE_MILLISECONDS = 120000; // 2min
/*
* name of the environment variable containing the read-only
* database names as CSV
*/
const replicaConfigLabel = 'REPLICAS';
// an array of read-only data base URLs
const readReplicas = configUtil.getReadReplicas(pe, replicaConfigLabel);
const DEFAULT_JOB_QUEUE_TTL_SECONDS = 3600;
/*
* If you're using worker dynos, you can set env vars PRIORITIZE_JOBS_FROM
* and/or DEPRIORITIZE_JOBS_FROM to comma-separated lists of ip addresses if
* you want to prioritize or deprioritize jobs from a particular user ip
* address (or multiple users' ip addresses). Has no effect if you're not
* using worker dynos.
*/
const prioritizeJobsFrom = configUtil.csvToArray(pe.PRIORITIZE_JOBS_FROM);
const deprioritizeJobsFrom = configUtil.csvToArray(pe.DEPRIORITIZE_JOBS_FROM);
// set time to live for "kue" jobs
const JOB_QUEUE_TTL_SECONDS = pe.TTL_KUE_JOBS || DEFAULT_JOB_QUEUE_TTL_SECONDS;
/*
* Assigns each of the different redis uses cases to a particular redis
* instance, if configured, or falls back to the primary redis instance.
*/
const redisUrls = {
cache: pe.REDIS_CACHE && pe[pe.REDIS_CACHE] ?
pe[pe.REDIS_CACHE] : (pe.REDIS_URL || DEFAULT_LOCAL_REDIS_URL),
limiter: pe.REDIS_LIMITER && pe[pe.REDIS_LIMITER] ?
pe[pe.REDIS_LIMITER] : (pe.REDIS_URL || DEFAULT_LOCAL_REDIS_URL),
pubsub: pe.REDIS_PUBSUB && pe[pe.REDIS_PUBSUB] ?
pe[pe.REDIS_PUBSUB] : (pe.REDIS_URL || DEFAULT_LOCAL_REDIS_URL),
queue: pe.REDIS_QUEUE && pe[pe.REDIS_QUEUE] ?
pe[pe.REDIS_QUEUE] : (pe.REDIS_URL || DEFAULT_LOCAL_REDIS_URL),
realtimeLogging: pe.REDIS_REALTIME_LOGGING && pe[pe.REDIS_REALTIME_LOGGING] ?
pe[pe.REDIS_REALTIME_LOGGING] : (pe.REDIS_URL || DEFAULT_LOCAL_REDIS_URL),
sampleStore: pe.REDIS_SAMPLE_STORE && pe[pe.REDIS_SAMPLE_STORE] ?
pe[pe.REDIS_SAMPLE_STORE] : (pe.REDIS_URL || DEFAULT_LOCAL_REDIS_URL),
session: pe.REDIS_SESSION && pe[pe.REDIS_SESSION] ?
pe[pe.REDIS_SESSION] : (pe.REDIS_URL || DEFAULT_LOCAL_REDIS_URL),
};
module.exports = {
api: {
defaults: {
limit: 10,
offset: 10,
},
swagger: {
doc: './api/v1/swagger.yaml',
router: {
controllers: './api/v1/controllers',
},
validator: {
validateResponse: true,
},
},
sessionSecret: 'refocusrockswithgreenowls',
},
db: {
adminProfile: {
name: 'Admin',
aspectAccess: 'rw',
lensAccess: 'rw',
perspectiveAccess: 'rw',
profileAccess: 'rw',
sampleAccess: 'rw',
subjectAccess: 'rw',
userAccess: 'rw',
},
adminUser: {
email: 'admin@refocus.admin',
name: 'admin@refocus.admin',
password: 'password',
},
modelDirName: 'model',
passwordHashSaltNumRounds: 8,
},
redis: {
channelName: 'focus',
instanceUrl: {
cache: redisUrls.cache,
limiter: redisUrls.limiter,
pubsub: redisUrls.pubsub,
queue: redisUrls.queue,
realtimeLogging: redisUrls.realtimeLogging,
sampleStore: redisUrls.sampleStore,
session: redisUrls.session,
},
},
// When adding new environment, consider adding it to /config/migrationConfig
// as well to enable database migraton in the environment.
environment: {
build: {
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
defaultNodePort: defaultPort,
host: '127.0.0.1',
ipWhitelist: iplist.push('::ffff:127.0.0.1'),
dialect: 'postgres',
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
development: {
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
defaultNodePort: defaultPort,
host: '127.0.0.1',
ipWhitelist: iplist,
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: true,
},
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
production: {
dbLogging: false, // console.log | false | ...
dbUrl: pe.DATABASE_URL,
ipWhitelist: iplist,
dialect: 'postgres',
protocol: 'postgres',
dialectOptions: {
ssl: true,
},
tokenSecret: pe.SECRET_TOKEN ||
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
testWhitelistLocalhost: {
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
defaultNodePort: defaultPort,
host: '127.0.0.1',
ipWhitelist: iplist,
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
testBlockAllhosts: {
dbLogging: false, // console.log | false | ...
dbUrl: defaultDbUrl,
defaultNodePort: defaultPort,
host: '127.0.0.1',
ipWhitelist: [''],
tokenSecret:
'7265666f637573726f636b7377697468677265656e6f776c7373616e6672616e',
},
},
checkTimeoutIntervalMillis: pe.CHECK_TIMEOUT_INTERVAL_MILLIS ||
DEFAULT_CHECK_TIMEOUT_INTERVAL_MILLIS,
CACHE_EXPIRY_IN_SECS,
JOB_QUEUE_TTL_SECONDS,
deprioritizeJobsFrom,
endpointToLimit,
httpMethodToLimit,
nodeEnv,
payloadLimit,
persistRedisSampleStoreMilliseconds:
pe.PERSIST_REDIS_SAMPLE_STORE_MILLISECONDS ||
DEFAULT_PERSIST_REDIS_SAMPLE_STORE_MILLISECONDS,
port,
prioritizeJobsFrom,
rateLimit,
rateWindow,
readReplicas,
};