-
Notifications
You must be signed in to change notification settings - Fork 29
/
config.js
executable file
·532 lines (526 loc) · 13.5 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
const convict = require('convict')
const conf = convict({
app: {
name: {
doc: 'The applicaton name',
format: String,
default: 'DADI API Repo Default'
}
},
publicUrl: {
host: {
doc:
'The host of the URL where the API instance can be publicly accessed at',
format: '*',
default: null,
env: 'URL_HOST'
},
port: {
doc:
'The port of the URL where the API instance can be publicly accessed at',
format: '*',
default: null,
env: 'URL_PORT'
},
protocol: {
doc:
'The protocol of the URL where the API instance can be publicly accessed at',
format: 'String',
default: 'http',
env: 'URL_PROTOCOL'
}
},
server: {
host: {
doc:
'Accept connections on the specified address. If the host is omitted, the server will accept connections on any IPv6 address (::) when IPv6 is available, or any IPv4 address (0.0.0.0) otherwise.',
format: '*',
default: null,
env: 'HOST'
},
port: {
doc:
'Accept connections on the specified port. A value of zero will assign a random port.',
format: Number,
default: 8081,
env: 'PORT'
},
redirectPort: {
doc: 'Port to redirect http connections to https from',
format: 'port',
default: 0,
env: 'REDIRECT_PORT'
},
protocol: {
doc: 'The protocol the web application will use',
format: String,
default: 'http',
env: 'PROTOCOL'
},
sslPassphrase: {
doc: 'The passphrase of the SSL private key',
format: String,
default: '',
env: 'SSL_PRIVATE_KEY_PASSPHRASE'
},
sslPrivateKeyPath: {
doc: 'The filename of the SSL private key',
format: String,
default: '',
env: 'SSL_PRIVATE_KEY_PATH'
},
sslCertificatePath: {
doc: 'The filename of the SSL certificate',
format: String,
default: '',
env: 'SSL_CERTIFICATE_PATH'
},
sslIntermediateCertificatePath: {
doc: 'The filename of an SSL intermediate certificate, if any',
format: String,
default: '',
env: 'SSL_INTERMEDIATE_CERTIFICATE_PATH'
},
sslIntermediateCertificatePaths: {
doc:
'The filenames of SSL intermediate certificates, overrides sslIntermediateCertificate (singular)',
format: Array,
default: [],
env: 'SSL_INTERMEDIATE_CERTIFICATE_PATHS'
}
},
datastore: {
doc:
'The name of the npm module that implements the data connector used for storing documents',
format: String,
default: '@dadi/api-mongodb'
},
auth: {
tokenUrl: {
doc: 'The endpoint used for token generation',
format: String,
default: '/token'
},
tokenTtl: {
doc: 'The amount of time (in seconds) which bearer tokens are valid for',
format: Number,
default: 1800
},
tokenKey: {
doc: 'The private key used to sign JWT tokens',
format: String,
default: '',
env: 'TOKEN_KEY'
},
accessCollection: {
doc:
'The name of the internal collection used to store aggregate permissions data',
format: String,
default: 'accessStore'
},
clientCollection: {
doc: 'The name of the internal collection used to store clients',
format: String,
default: 'clientStore'
},
keyAccessCollection: {
doc:
'The name of the internal collection used to store aggregate permissions data for keys',
format: String,
default: 'keyAccessStore'
},
keyCollection: {
doc: 'The name of the internal collection used to store access keys',
format: String,
default: 'keyStore'
},
roleCollection: {
doc: 'The name of the internal collection used to store roles',
format: String,
default: 'roleStore'
},
datastore: {
doc:
'The name of the npm module that implements the data connector used for authentication',
format: String,
default: '@dadi/api-mongodb'
},
database: {
doc: 'The name of the database used to store authentication data',
format: String,
default: 'test',
env: 'DB_AUTH_NAME'
},
hashSecrets: {
doc: 'Whether to hash client secrets',
format: Boolean,
default: true
},
saltRounds: {
doc: 'The number of rounds to go through when hashing a password',
format: Number,
default: 10
},
resetTokenTtl: {
doc: 'The amount of time (in seconds) which reset tokens are valid for',
format: Number,
default: 600
}
},
search: {
database: {
doc:
'The name of the database to use for storing and querying indexed documents',
format: String,
default: 'search',
env: 'DB_SEARCH_NAME'
},
datastore: {
doc: 'The datastore to use for storing and querying indexed documents',
format: String,
default: ''
},
enabled: {
doc: 'If true, API responds to collection /search endpoints',
format: Boolean,
default: false
},
indexCollection: {
doc:
'The name of the datastore collection that will hold the index of word matches',
format: String,
default: 'searchIndex'
},
minQueryLength: {
doc: 'Minimum search string length',
format: Number,
default: 3
},
wordCollection: {
doc:
'The name of the datastore collection that will hold tokenized words',
format: String,
default: 'searchWords'
}
},
caching: {
ttl: {
doc: '',
format: Number,
default: 300
},
directory: {
enabled: {
doc: 'If enabled, cache files will be saved to the filesystem',
format: Boolean,
default: true
},
path: {
doc: 'The relative path to the cache directory',
format: String,
default: './cache/api'
},
extension: {
doc: 'The extension to use for cache files',
format: String,
default: 'json'
},
autoFlush: {
doc: '',
format: Boolean,
default: true
},
autoFlushInterval: {
doc: '',
format: Number,
default: 60
}
},
redis: {
enabled: {
doc:
'If enabled, cache files will be saved to the specified Redis server',
format: Boolean,
default: false,
env: 'REDIS_ENABLED'
},
host: {
doc: 'The Redis server host',
format: String,
default: '127.0.0.1',
env: 'REDIS_HOST'
},
port: {
doc: 'The port for the Redis server',
format: 'port',
default: 6379,
env: 'REDIS_PORT'
},
password: {
doc: '',
format: String,
default: '',
env: 'REDIS_PASSWORD'
}
}
},
logging: {
enabled: {
doc: 'If true, logging is enabled using the following settings.',
format: Boolean,
default: true
},
level: {
doc: 'Sets the logging level.',
format: ['debug', 'info', 'warn', 'error', 'trace'],
default: 'info'
},
path: {
doc: 'The absolute or relative path to the directory for log files.',
format: String,
default: './log'
},
filename: {
doc: 'The name to use for the log file, without extension.',
format: String,
default: 'api'
},
extension: {
doc: 'The extension to use for the log file.',
format: String,
default: 'log'
},
accessLog: {
enabled: {
doc:
'If true, HTTP access logging is enabled. The log file name is similar to the setting used for normal logging, with the addition of "access". For example `api.access.log`.',
format: Boolean,
default: true
},
kinesisStream: {
doc: 'An AWS Kinesis stream to write to log records to.',
format: String,
default: '',
env: 'KINESIS_STREAM'
}
}
},
paths: {
collections: {
doc: 'The relative or absolute path to collection specification files',
format: String,
default: 'workspace/collections'
},
endpoints: {
doc: 'The relative or absolute path to custom endpoint files',
format: String,
default: 'workspace/endpoints'
},
hooks: {
doc: 'The relative or absolute path to hook specification files',
format: String,
default: 'workspace/hooks'
},
passwordReset: {
doc: 'The path to the password reset handler file',
format: String,
default: ''
}
},
feedback: {
doc: '',
format: Boolean,
default: false
},
status: {
enabled: {
doc: 'If true, status endpoint is enabled.',
format: Boolean,
default: false
},
routes: {
doc:
'An array of routes to test. Each route object must contain properties `route` and `expectedResponseTime`.',
format: Array,
default: []
}
},
media: {
defaultBucket: {
doc: 'The name of the default media bucket',
format: String,
default: 'mediaStore'
},
buckets: {
doc: 'The names of media buckets to be used',
format: Array,
default: []
},
tokenSecret: {
doc: 'The secret key used to sign and verify tokens when uploading media',
format: String,
default: 'catboat-beatific-drizzle'
},
tokenExpiresIn: {
doc:
'The duration a signed token is valid for. Expressed in seconds or a string describing a time span (https://github.com/zeit/ms). Eg: 60, "2 days", "10h", "7d"',
format: '*',
default: '1h'
},
storage: {
doc: 'Determines the storage type for uploads',
format: ['disk', 's3'],
default: 'disk'
},
basePath: {
doc: 'Sets the root directory for uploads',
format: String,
default: 'workspace/media'
},
pathFormat: {
doc:
'Determines the format for the generation of subdirectories to store uploads',
format: ['none', 'date', 'datetime', 'sha1/4', 'sha1/5', 'sha1/8'],
default: 'date'
},
s3: {
accessKey: {
doc:
'The access key used to connect to an S3-compatible storage provider',
format: String,
default: '',
env: 'AWS_S3_ACCESS_KEY'
},
secretKey: {
doc:
'The secret key used to connect to an S3-compatible storage provider',
format: String,
default: '',
env: 'AWS_S3_SECRET_KEY'
},
bucketName: {
doc: 'The name of the S3 bucket in which to store uploads',
format: String,
default: '',
env: 'AWS_S3_BUCKET_NAME'
},
region: {
doc: 'The region for an S3-compatible storage provider',
format: String,
default: '',
env: 'AWS_S3_REGION'
},
endpoint: {
doc: 'The endpoint for an S3-compatible storage provider',
format: String,
default: ''
}
},
publicUrl: {
doc: 'The base URL where media assets can be publicly accessed at',
format: 'String',
default: null,
env: 'MEDIA_PUBLIC_URL'
}
},
env: {
doc: 'The applicaton environment.',
format: String,
default: 'development',
env: 'NODE_ENV',
arg: 'node_env'
},
cluster: {
doc:
'If true, API runs in cluster mode, starting a worker for each CPU core',
format: Boolean,
default: false
},
cors: {
doc:
'If true, responses will include headers for cross-domain resource sharing',
format: Boolean,
default: true
},
internalFieldsPrefix: {
doc: 'The character to be used for prefixing internal fields',
format: 'String',
default: '_'
},
databaseConnection: {
maxRetries: {
doc:
'The maximum number of times to reconnection attempts after a database fails',
format: Number,
default: 10
}
},
i18n: {
defaultLanguage: {
doc: 'ISO-639-1 code of the default language',
format: String,
default: 'en'
},
languages: {
doc: 'List of ISO-639-1 codes for the supported languages',
format: Array,
default: []
},
fieldCharacter: {
doc: 'Special character to denote a translated field',
format: String,
default: ':'
}
},
featureQuery: {
enabled: {
doc: 'Whether feature query via custom headers is enabled',
format: Boolean,
default: true
}
},
workQueue: {
debounceTime: {
doc:
'The amount of idle time (in ms) required for the work queue to start a background job',
format: Number,
default: 500
},
pollingTime: {
doc:
'The interval (in ms) at which the work queue checks for new background jobs',
format: Number,
default: 200
}
},
schemas: {
collection: {
doc: 'The name of the internal collection to store collection schemas',
format: String,
default: 'schemas'
},
loadSeeds: {
doc: 'Whether to scan the workspace directory for collection seed files',
format: Boolean,
default: true
}
}
})
// Load environment dependent configuration
const env = conf.get('env')
conf.loadFile('./config/config.' + env + '.json')
// Load domain-specific configuration
conf.updateConfigDataForDomain = function(domain) {
const domainConfig = './config/' + domain + '.json'
try {
conf.loadFile(domainConfig)
} catch (err) {
if (err.code !== 'ENOENT') {
console.log(err)
}
}
}
module.exports = conf
module.exports.configPath = function() {
return './config/config.' + conf.get('env') + '.json'
}