This repository has been archived by the owner on May 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.js
98 lines (89 loc) · 2.9 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
import signale from 'signale';
import convict from 'convict';
import rc from 'rc';
import { MODE_PLAYER } from './modes.js';
const processEnv = process.env;
const isPlayerMode = processEnv['WEB_MYNA_MODE'] === MODE_PLAYER || !processEnv['WEB_MYNA_MODE'];
const globalConfiguration = rc('webmyna', { apis: [], recordingsPath: null });
convict.addFormat({
name: 'apis',
validate: (apis, schema) => {
if (!Array.isArray(apis)) {
throw new Error('must be of type Array');
}
apis.map((api, index) => {
const tokenName = api.name ? `${api.name.toUpperCase().replace(/-/g, '_')}_TOKEN` : null;
signale.debug(tokenName);
if (tokenName || isPlayerMode) {
const apiToken = processEnv[tokenName];
apis[index].token = isPlayerMode ? 'webMynaPlayerToken' : apiToken;
}
});
for (const api of apis) {
convict(schema.children)
.load(api)
.validate();
}
},
});
const config = convict({
apis: {
doc: 'A collection of APIs to mock.',
format: 'apis',
default: [],
children: {
name: {
doc: 'The API name, used as id. So it have to be a slug format, but steel readable',
format: String,
default: null,
},
url: {
doc: 'The API main endpoint URL',
format: 'url',
default: null,
},
token: {
doc: 'Value of the authorization token to add in http headers',
format: String,
default: null,
},
tokenKey: {
doc: 'Name of the http header for authentification',
format: String,
default: 'authorization',
},
tokenPrefix: {
doc: 'Token prefix into the http header value',
format: String,
default: 'Bearer',
},
},
},
env: {
doc: 'The application environment.',
format: ['production', 'development', 'test'],
default: 'development',
env: 'NODE_ENV',
},
mode: {
doc: 'Recording mode in which WebMyna is started',
format: ['player', 'recorder'],
default: 'player',
env: 'WEB_MYNA_MODE',
},
proxyPort: {
doc: 'The proxy port to bind.',
format: 'port',
default: globalConfiguration.proxyPort || 8080,
env: 'WEB_MYNA_PROXY_PORT',
},
recordingsPath: {
doc: 'path to the main recording folder',
format: String,
default: globalConfiguration.recordingsPath || '/tmp/webmyna',
env: 'WEB_MYNA_RECORDINGS_PATH',
},
});
config.load({ apis: globalConfiguration.apis });
config.validate({ allowed: 'strict' });
export default config.getProperties();