-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
551 lines (545 loc) · 13.3 KB
/
config.js
File metadata and controls
551 lines (545 loc) · 13.3 KB
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
var convict = require('convict')
var fs = require('fs')
var path = require('path')
// Define a schema
var conf = convict({
server: {
host: {
doc: 'The IP address the application will run on',
format: 'ipaddress',
default: '0.0.0.0'
},
port: {
doc: 'The port number the application will bind to',
format: 'port',
default: 8080
},
name: {
doc: 'Server name',
format: String,
default: 'Image Handle'
},
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"
}
},
logging: {
enabled: {
doc: 'If true, logging is enabled using the following settings.',
format: Boolean,
default: false
},
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: 'cdn'
},
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 `cdn.access.log`.",
format: Boolean,
default: true
}
}
},
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'
}
},
notFound: {
statusCode: {
doc: 'If set, overrides the status code in the case of a 404',
format: Number,
default: 404
},
images: {
enabled: {
doc: 'If true, returns a default image when request returns a 404',
format: Boolean,
default: false
},
path: {
doc: 'The path to the default image',
format: String,
default: './images/missing.png'
}
}
},
images: {
directory: {
enabled: {
doc: 'If true, image files will be loaded from the filesystem',
format: Boolean,
default: false
},
path: {
doc: 'The path to the image directory',
format: String,
default: './images'
}
},
s3: {
enabled: {
doc: 'If true, image files will be requested from Amazon S3',
format: Boolean,
default: false
},
accessKey: {
doc: '',
format: String,
default: '',
env: 'AWS_S3_IMAGES_ACCESS_KEY'
},
secretKey: {
doc: '',
format: String,
default: '',
env: 'AWS_S3_IMAGES_SECRET_KEY'
},
bucketName: {
doc: '',
format: String,
default: '',
env: 'AWS_S3_IMAGES_BUCKET_NAME'
},
region: {
doc: '',
format: String,
default: '',
env: 'AWS_S3_IMAGES_REGION'
}
},
remote: {
enabled: {
doc: 'If true, image files will be requested from a remote host',
format: Boolean,
default: false
},
path: {
doc: 'The remote host to request images from, for example http://media.example.com',
format: String,
default: ''
}
}
},
assets: {
directory: {
enabled: {
doc: 'If true, asset files will be loaded from the filesystem',
format: Boolean,
default: false
},
path: {
doc: '',
format: String,
default: './public'
}
},
s3: {
enabled: {
doc: 'If true, asset files will be requested from Amazon S3',
format: Boolean,
default: false
},
accessKey: {
doc: '',
format: String,
default: '',
env: 'AWS_S3_ASSETS_ACCESS_KEY'
},
secretKey: {
doc: '',
format: String,
default: '',
env: 'AWS_S3_ASSETS_SECRET_KEY'
},
bucketName: {
doc: '',
format: String,
default: '',
env: 'AWS_S3_ASSETS_BUCKET_NAME'
},
region: {
doc: '',
format: String,
default: '',
env: 'AWS_S3_ASSETS_REGION'
}
},
remote: {
enabled: {
doc: 'If true, asset files will be requested from a remote host',
format: Boolean,
default: false
},
path: {
doc: 'The remote host to request assets from, for example http://media.example.com',
format: String,
default: ''
}
}
},
caching: {
ttl: {
doc: '',
format: Number,
default: 3600
},
directory: {
enabled: {
doc: 'If true, 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/'
}
},
redis: {
enabled: {
doc: 'If true, cache files will be saved to the specified Redis server',
format: Boolean,
default: false
},
host: {
doc: 'The Redis server host',
format: String,
default: '',
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'
}
}
},
status: {
enabled: {
doc: "If true, status endpoint is enabled.",
format: Boolean,
default: true
},
requireAuthentication: {
doc: "If true, status endpoint requires authentication.",
format: Boolean,
default: true
},
standalone: {
doc: "If true, status endpoint will run on an standalone address/port.",
format: Boolean,
default: false
},
port: {
doc: "Accept connections on the specified port. A value of zero will assign a random port.",
format: Number,
default: 8003,
env: "STATUS_PORT"
},
routes: {
doc: "An array of routes to test. Each route object must contain properties `route` and `expectedResponseTime`. Note, `expectedResponseTime` is seconds.",
format: Array,
default: [
{
route: '/test.jpg?format=png&quality=50&width=800&height=600',
expectedResponseTime: 0.025
}
]
}
},
security: {
maxWidth: {
doc: '',
format: Number,
default: 2048
},
maxHeight: {
doc: '',
format: Number,
default: 1024
}
},
auth: {
tokenUrl: {
doc: '',
format: String,
default: '/token'
},
clientId: {
doc: '',
format: String,
default: '1235488',
env: "AUTH_TOKEN_ID"
},
secret: {
doc: '',
format: String,
default: 'asd544see68e52',
env: "AUTH_TOKEN_SECRET"
},
tokenTtl: {
doc: '',
format: Number,
default: 1800,
env: "AUTH_TOKEN_TTL"
}
},
cloudfront: {
enabled: {
doc: '',
format: Boolean,
default: false
},
accessKey: {
doc: '',
format: String,
default: '',
env: "CLOUDFRONT_ACCESS_KEY"
},
secretKey: {
doc: '',
format: String,
default: '',
env: "CLOUDFRONT_SECRET_KEY"
},
distribution: {
doc: '',
format: String,
default: '',
env: "CLOUDFRONT_DISTRIBUTION"
}
},
cluster: {
doc: 'If true, CDN runs in cluster mode, starting a worker for each CPU core',
format: Boolean,
default: false
},
paths: {
doc: "",
format: Object,
default: {
processors: __dirname + '/workspace/processors',
recipes: __dirname + '/workspace/recipes',
routes: __dirname + '/workspace/routes'
}
},
gzip: {
doc: "If true, uses gzip compression and adds a 'Content-Encoding:gzip' header to the response",
format: Boolean,
default: true
},
headers: {
useGzipCompression: {
doc: "If true, uses gzip compression and adds a 'Content-Encoding:gzip' header to the response.",
format: Boolean,
default: true
},
cacheControl: {
doc: "A set of cache control headers based on specified mimetypes or paths",
format: Object,
default: {
"default": "public, max-age=3600",
"paths": [],
"mimetypes": [
{"text/css": "public, max-age=86400"},
{"text/javascript": "public, max-age=86400"},
{"application/javascript": "public, max-age=86400"}
]
}
}
},
upload: {
enabled: {
doc: 'If true, files can be uploaded to CDN with a POST request',
format: Boolean,
default: false
},
requireAuthentication: {
doc: 'If true, POST requests must include the authentication credentials specified in the `auth` property of the configuration file',
format: Boolean,
default: true
},
extractColours: {
doc: 'If true, extracts colour information from the uploaded image and returns as JSON along with the file upload result',
format: Boolean,
default: true
},
pathFormat: {
doc: 'Determines the format for subdirectories that are created to store uploads',
format: ['none', 'date', 'datetime', 'sha1/4', 'sha1/5', 'sha1/8'],
default: 'date'
}
},
feedback: {
doc: '',
format: Boolean,
default: false
},
robots: {
doc: 'The path to a robots.txt file',
format: String,
default: ''
},
env: {
doc: 'The applicaton environment.',
format: ['production', 'development', 'test', 'qa'],
default: 'development',
env: 'NODE_ENV',
arg: 'node_env'
},
geolocation: {
enabled: {
doc: 'Enable geolocation',
format: Boolean,
default: false
},
method: {
doc: 'Method to use for geolocation',
format: ['maxmind', 'remote'],
default: 'maxmind'
},
maxmind: {
countryDbPath: {
doc: 'Path to Maxmind country database',
format: String,
default: __dirname + '/vendor/maxmind-country.mmdb'
}
},
remote: {
url: {
doc: 'Remote URL to be used for geolocation. {key}, {secret} and {ip} will be replaced by the API key, secret and IP to locate, respectively',
format: String,
default: ''
},
key: {
doc: 'Key to be used with remote geolocation service',
format: String,
default: '',
env: 'GEOLOCATION_REMOTE_KEY'
},
secret: {
doc: 'Secret to be used with remote geolocation service',
format: String,
default: '',
env: 'GEOLOCATION_REMOTE_SECRET'
},
countryPath: {
doc: 'Path to the country code within the response object',
format: String,
default: 'location.country.isoCode'
}
}
},
network: {
url: {
doc: 'Remote URL to be used for network test service. {key}, {secret} and {ip} will be replaced by the API key, secret and IP to locate, respectively',
format: String,
default: ''
},
key: {
doc: 'Key to be used with network test service',
format: String,
default: '',
env: 'NETWORK_REMOTE_KEY'
},
secret: {
doc: 'Secret to be used with network test service',
format: String,
default: '',
env: 'NETWORK_REMOTE_SECRET'
},
path: {
doc: 'Path to the network type within the response object',
format: String,
default: 'speed.connectionType'
}
}
})
// Load environment dependent configuration
var env = conf.get('env')
conf.loadFile('./config/config.' + env + '.json')
// Perform validation
conf.validate({strict: false})
// Update Config JSON file by domain name
conf.updateConfigDataForDomain = function (domain) {
if (fs.existsSync(path.resolve(__dirname + '/workspace/domain-loader/' + domain + '.config.' + env + '.json'))) {
conf.loadFile(__dirname + '/workspace/domain-loader/' + domain + '.config.' + env + '.json')
}
}
module.exports = conf
module.exports.configPath = function () {
return './config/config.' + conf.get('env') + '.json'
}