Repository navigation
Expand file tree
/
Copy pathconfig.js
More file actions
82 lines (75 loc) · 1.72 KB
/
Copy pathconfig.js
File metadata and controls
82 lines (75 loc) · 1.72 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
import envSchema from 'env-schema'
const schema = {
type: 'object',
properties: {
prefix: {
type: 'string',
default: ''
},
autoloads: {
type: 'array',
default: []
},
swagger: {
type: 'object',
default: {},
properties: {
routePrefix: {
type: 'string'
// no default, we set it dynamically below if not set
},
exposeRoute: {
default: true
},
openapi: {
default: {}
},
scalar: { default: {} }
}
},
health: {
type: 'object',
default: {},
properties: {
exposeStatusRoute: {
default: true
// default true, we set route dynamically below if not explicitely set
},
maxEventLoopDelay: {
default: 1000
},
maxHeapUsedBytes: {
default: 256 * 1024 * 1024
},
maxRssBytes: {
default: 512 * 1024 * 1024
},
retryAfter: {
default: 50
}
}
},
contentSecurityPolicy: {
type: ['boolean', 'object'],
// disable CSR as default, as we won't know any options from api side
default: false
}
}
}
export default (opts) => {
if (opts.healthCheck && !opts.health) {
opts.health = opts.healthCheck
}
const config = envSchema({
schema,
data: opts
})
// set swagger route prefix to default, if not set:
config.swagger.routePrefix
= config.swagger.routePrefix ?? `${config.prefix}/docs`
// set healthcheck route to default, if enabled, but not set:
if (config.health.exposeStatusRoute === true) {
config.health.exposeStatusRoute = `${config.prefix}/health`
}
return config
}