This repository has been archived by the owner on Sep 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
executable file
·392 lines (387 loc) · 9.83 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
var convict = require('convict')
var fs = require('fs')
var 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: "",
format: String,
default: '@dadi/api-mongodb'
},
auth: {
tokenUrl: {
doc: '',
format: String,
default: '/token'
},
tokenTtl: {
doc: '',
format: Number,
default: 1800
},
clientCollection: {
doc: '',
format: String,
default: 'clientStore'
},
tokenCollection: {
doc: '',
format: String,
default: "tokenStore"
},
datastore: {
doc: "",
format: String,
default: '@dadi/api-mongodb'
},
database: {
doc: '',
format: String,
default: 'test',
env: 'DB_AUTH_NAME'
},
cleanupInterval: {
doc: 'The interval (in seconds) at which the token store will delete expired tokens from the database',
format: Number,
default: 3600
}
},
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/web'
},
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: __dirname + '/workspace/collections'
},
endpoints: {
doc: 'The relative or absolute path to custom endpoint files',
format: String,
default: __dirname + '/workspace/endpoints'
},
hooks: {
doc: 'The relative or absolute path to hook specification files',
format: String,
default: __dirname + '/workspace/hooks'
}
},
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: []
}
},
query: {
useVersionFilter: {
doc: 'If true, the API version parameter is extracted from the request URL and passed to the database query',
format: Boolean,
default: false
}
},
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 AWS access key used to connect to S3',
format: String,
default: '',
env: 'AWS_S3_ACCESS_KEY'
},
secretKey: {
doc: 'The AWS secret key used to connect to S3',
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 AWS region',
format: String,
default: '',
env: 'AWS_S3_REGION'
}
}
},
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: false
},
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
}
}
})
// Load environment dependent configuration
var env = conf.get('env')
conf.loadFile('./config/config.' + env + '.json')
// Load domain-specific configuration
conf.updateConfigDataForDomain = function(domain) {
var domainConfig = './config/' + domain + '.json'
try {
var stats = fs.statSync(domainConfig)
// no error, file exists
conf.loadFile(domainConfig)
}
catch(err) {
if (err.code === 'ENOENT') {
//console.log('No domain-specific configuration file: ' + domainConfig)
}
else {
console.log(err)
}
}
}
module.exports = conf
module.exports.configPath = function() {
return './config/config.' + conf.get('env') + '.json'
}