-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconfig.js
555 lines (548 loc) · 14.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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
const convict = require('convict')
const fs = require('fs')
const path = require('path')
// Set folder location differently if an npm install
const installRoot = ~process.cwd().indexOf('node_modules')
? __dirname
: process.cwd()
// Define a schema
const conf = convict({
app: {
name: {
doc: 'The applicaton name',
format: String,
default: 'DADI Web (Repo Default)'
}
},
server: {
host: {
doc: 'The IP address the web application will run on',
format: '*',
default: '0.0.0.0'
},
port: {
doc: 'The port the web application will bind to',
format: 'port',
default: 8080,
env: 'PORT'
},
redirectPort: {
doc: 'Port to redirect http connections to https from',
format: 'port',
default: 0,
env: 'REDIRECT_PORT'
},
name: {
doc: 'The server name.',
format: String,
default: 'DADI (Web)'
},
socketTimeoutSec: {
doc: 'The number of seconds to wait before closing an idle socket',
format: Number,
default: 120
},
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'
},
enableHTTP2: {
doc: 'When `server.protocol = https` use http2 as the primary response method. Fallback to http1 for unsupported clients.',
format: Boolean,
default: true
}
},
auth: {
tokenUrl: {
doc: '',
format: String,
default: '/token'
},
protocol: {
doc: '',
format: String,
default: 'http'
},
clientId: {
doc: '',
format: String,
default: 'testClient',
env: 'AUTH_TOKEN_ID'
},
secret: {
doc: '',
format: String,
default: 'superSecret',
env: 'AUTH_TOKEN_SECRET'
}
},
api: {
doc: 'Any apis and their auth for use in datasources.',
format: Object,
default: {}
},
aws: {
accessKeyId: {
doc: '',
format: String,
default: '',
env: 'AWS_ACCESS_KEY'
},
secretAccessKey: {
doc: '',
format: String,
default: '',
env: 'AWS_SECRET_KEY'
},
region: {
doc: '',
format: String,
default: '',
env: 'AWS_REGION'
}
},
caching: {
ttl: {
doc: 'The time, in seconds, after which cached data is considered stale',
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/web'
},
extension: {
doc: 'The extension to use for cache files',
format: String,
default: 'html'
}
},
redis: {
enabled: {
doc:
'If enabled, cache files will be saved to the specified Redis server',
format: Boolean,
default: false
},
cluster: {
doc: '',
format: Boolean,
default: false
},
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'
}
}
},
headers: {
useCompression: {
doc:
"If true, uses br or gzip compression where available and adds a 'Content-Encoding: [br|gzip]' header to the response.",
format: Boolean,
default: true
},
cacheControl: {
doc:
"A set of custom cache control headers for different content types. For example 'cacheControl': { 'text/css': 'public, max-age=1000' }",
format: Object,
default: {
'image/png': 'public, max-age=86400',
'image/jpeg': 'public, max-age=86400',
'text/css': 'public, max-age=86400',
'text/javascript': 'public, max-age=86400',
'application/javascript': 'public, max-age=86400',
'image/x-icon': 'public, max-age=31536000000'
}
}
},
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: 'web'
},
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 `web.access.log`.",
format: Boolean,
default: true
},
kinesisStream: {
doc: 'An AWS Kinesis stream to write to log records to.',
format: String,
default: ''
}
},
sentry: {
dsn: {
doc:
"The 'DSN' to use for logging errors and events to a Sentry server. It should be similar to 'https://693ef18da3184cffa82144fde2979cbc:[email protected]/59524'.",
format: String,
default: ''
}
}
},
globalEvents: {
doc: 'Events to be loaded on every request.',
format: Array,
default: []
},
globalPostProcessors: {
doc: 'Post-render processors to be run on every request.',
format: Array,
default: []
},
global: {
doc: '',
format: Object,
default: {}
},
paths: {
doc: '',
format: Object,
default: {
datasources: path.join(installRoot, '/workspace/datasources'),
events: path.join(installRoot, '/workspace/events'),
processors: path.join(installRoot, '/workspace/processors'),
middleware: path.join(installRoot, '/workspace/middleware'),
pages: path.join(installRoot, '/workspace/pages'),
public: path.join(installRoot, '/workspace/public'),
routes: path.join(installRoot, '/workspace/routes'),
tokenWallets: path.join(installRoot, '/.wallet')
}
},
sessions: {
enabled: {
doc: '',
format: Boolean,
default: false
},
name: {
doc: "The session cookie name. The default value is 'dadiweb.sid'",
format: String,
default: 'dadiweb.sid'
},
secret: {
doc:
'This is the secret used to sign the session ID cookie. This can be either a string for a single secret, or an array of multiple secrets. If an array of secrets is provided, only the first element will be used to sign the session ID cookie, while all the elements will be considered when verifying the signature in requests.',
format: String,
default: 'dadiwebsecretsquirrel',
env: 'SESSION_SECRET'
},
resave: {
doc:
'Forces the session to be saved back to the session store, even if the session was never modified during the request.',
format: Boolean,
default: false
},
saveUninitialized: {
doc:
"Forces a session that is 'uninitialized' to be saved to the store. A session is uninitialized when it is new but not modified.",
format: Boolean,
default: false
},
store: {
doc:
'The session store instance, defaults to a new MemoryStore instance.',
format: String,
default: ''
},
cookie: {
maxAge: {
doc:
"Set the cookie’s expiration as an interval of seconds in the future, relative to the time the browser received the cookie. Null means no 'expires' parameter is set so the cookie becomes a browser-session cookie. When the user closes the browser the cookie (and session) will be removed.",
format: '*',
default: 60000
},
secure: {
doc: '',
format: Boolean,
default: false
}
}
},
rewrites: {
datasource: {
doc: '',
format: String,
default: ''
},
loadDatasourceAsFile: {
doc: '',
format: Boolean,
default: false
},
datasourceRefreshTime: {
format: Number,
default: 5,
doc: 'How often to refresh the datasource in minutes'
},
path: {
doc: '',
format: String,
default: ''
},
forceLowerCase: {
doc: 'If true, converts URLs to lowercase and redirects',
format: Boolean,
default: false
},
forceTrailingSlash: {
doc: 'If true, adds a trailing slash to URLs and redirects',
format: Boolean,
default: false
},
stripIndexPages: {
doc:
"A set of filenames to remove from URLs. For example ['index.php', 'default.aspx']",
format: Array,
default: []
},
forceDomain: {
doc: 'The domain to force requests to',
format: Object,
default: {
hostname: '',
port: 80,
type: 301
}
}
},
security: {
trustProxy: {
doc:
'If true, trusts the values specified in X-Forwarded-* headers, such as protocol and client IP address',
format: '*',
default: true
},
transportSecurity: {
doc:
'If true, requires requests to be secure. Overridden if server.protocol is set to https.',
format: '*',
default: false
},
csrf: {
doc:
'If true, a CSRF token will be provided, and all form submissions must include this as _csrf',
format: '*',
default: false
}
},
uploads: {
enabled: {
doc:
'If true, files uploaded via a form a saved to disk and added to `req.files`',
format: Boolean,
default: false
},
destinationPath: {
doc: 'The destination directory for uploaded files',
format: String,
default: 'workspace/uploads'
},
hashFilename: {
doc: 'If true, hashes the original filename using SHA1',
format: Boolean,
default: false
},
hashKey: {
doc:
'The key to use when hashing the filename, if `hashFilename` is true',
format: String,
default: ''
},
prefix: {
doc:
'If set, the uploaded file is prefixed with the specified value. Overrides "prefixWithFieldName".',
format: String,
default: ''
},
prefixWithFieldName: {
doc: 'If true, the uploaded file is prefixed with the form field name',
format: Boolean,
default: false
},
whitelistRoutes: {
doc: 'An array of routes which can accept file uploads',
format: Array,
default: []
}
},
env: {
doc: 'The applicaton environment.',
format: String,
default: 'development',
env: 'NODE_ENV',
arg: 'node_env'
},
virtualHosts: {
doc: 'Allows serving multiple domains from a single instance of DADI Web',
format: Object,
default: {}
},
virtualDirectories: {
doc:
'Allows specifying folders where additional static content may reside. An array entry should like look { "path": "data/legacy_features", "index": "default.html", "forceTrailingSlash": false }',
format: Array,
default: []
},
allowJsonView: {
doc:
'If true, allows appending ?json=true to the querystring to view the raw JSON output for each page.',
format: Boolean,
default: false
},
allowDebugView: {
doc:
'If true, allows appending ?debug= to the querystring to view how the page is constructed,',
format: Boolean,
default: false
},
toobusy: {
enabled: {
doc:
'If true, server will respond with HTTP 503 if the server is deemed too busy.',
format: Boolean,
default: false
},
maxLag: {
doc:
"The maximum amount of time in milliseconds that the event queue is behind before we consider the process 'too busy'.",
format: Number,
default: 70
},
interval: {
doc: 'The time in milliseconds between each latency check.',
format: Number,
default: 500
}
},
cluster: {
doc:
'If true, Web runs in cluster mode, starting a worker for each CPU core',
format: Boolean,
default: true
},
debug: {
doc:
'If true, debug mode is enabled and a panel containing the JSON loaded for each page is displayed alongside the normal content.',
format: Boolean,
default: false
},
data: {
preload: {
doc: 'An array of datasources to load at startup',
format: Array,
default: []
}
},
engines: {
doc: 'Engine-specific configuration parameters',
format: Object,
default: {}
},
status: {
doc: '@dadi/status module options',
format: Object,
default: {}
}
})
// Load environment dependent configuration
var env = conf.get('env')
conf.loadFile('./config/config.' + env + '.json')
// Load domain-specific configuration
conf.updateConfigDataForDomain = function (domain) {
return new Promise((resolve, reject) => {
var domainConfig = './config/' + domain + '.json'
fs.stat(domainConfig, (err, stats) => {
if (err && err.code === 'ENOENT') {
// No domain-specific configuration file
return reject(err)
}
// no error, file exists
conf.loadFile(domainConfig)
return resolve()
})
})
}
module.exports = conf
module.exports.configPath = function () {
var env = conf.get('env') || process.env['NODE_ENV']
return './config/config.' + env + '.json'
}