forked from AHRQ-CDS/AHRQ-CDS-Connect-Authoring-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
180 lines (174 loc) · 4.97 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
const convict = require('convict');
const validator = require('validator');
const fs = require('fs');
function laxUrl(...protocols) {
return (val) => {
if (!validator.isURL(val, { protocols, require_tld: false, allow_underscores: true })) {
throw new Error(`must be a URL with protocol from {${protocols}}`);
}
};
}
// Define the schema
const config = convict({
env: {
doc: 'The applicaton environment.',
format: ['production', 'development', 'test'],
default: 'development',
env: 'NODE_ENV'
},
mongo: {
url: {
doc: 'The connection URL for MongoDB.',
format: laxUrl('mongodb'),
default: 'mongodb://localhost/cds_authoring',
env: 'MONGO_URL',
}
},
migrations: {
active: {
doc: 'Indicates if migrations are automatically applied on startup',
format: 'Boolean',
default: true,
env: 'MIGRATIONS_ACTIVE',
}
},
repo: {
url: {
doc: 'The URL to the CDS Connect repository.',
format: laxUrl('http', 'https'),
default: 'https://cdsconnect.ahrqdev.org',
env: 'REPO_URL',
},
publish: {
active: {
doc: 'Indicates if publishing to the repo is active.',
format: 'Boolean',
default: false,
env: 'REPO_PUBLISH_ACTIVE',
}
}
},
cqlToElm: {
url: {
doc: 'The URL endpoint for the CQL translation service.',
format: laxUrl('http', 'https'),
default: 'http://localhost:8080/cql/translator',
env: 'CQL_TO_ELM_URL',
},
active: {
doc: 'Indicates if CQL translation is active (only disable for dev)',
format: 'Boolean',
default: true,
env: 'CQL_TO_ELM_ACTIVE',
}
},
auth: {
session: {
secret: {
doc: 'The session secret.',
format: 'String',
default: 'secret',
env: 'AUTH_SESSION_SECRET',
sensitive: true
}
},
ldap: {
active: {
doc: 'Indicates if the LDAP authentication strategy should be used',
format: 'Boolean',
default: true,
env: 'AUTH_LDAP_ACTIVE',
},
server: {
doc: 'LDAP config passed into passport for authentication. The tokens `{{username}}` and `{{password}}`' +
'will be replaced during authentication with the authenticating username and password.',
url: {
doc: 'The LDAP connection URL.',
format: laxUrl('ldap', 'ldaps'),
default: 'ldap://localhost:389',
env: 'AUTH_LDAP_URL',
},
bindDN: {
doc: 'The LDAP bind DN.',
format: 'String',
default: 'cn=root',
env: 'AUTH_LDAP_BIND_DN',
},
bindCredentials: {
doc: 'The LDAP bind credentials.',
format: 'String',
default: 'secret',
env: 'AUTH_LDAP_BIND_CREDENTIALS',
sensitive: true
},
searchBase: {
doc: 'The LDAP search base.',
format: 'String',
default: 'ou=passport-ldapauth',
env: 'AUTH_LDAP_SEARCH_BASE',
},
searchFilter: {
doc: 'The LDAP search filter.',
format: 'String',
default: '(uid={{username}})',
env: 'AUTH_LDAP_SEARCH_FILTER',
}
}
},
local: {
active: {
doc: 'Indicates if the local authentication strategy should be used. If active, a ' +
'`config/local-users.json` file must be created to specify credentials.',
format: 'Boolean',
default: false,
env: 'AUTH_LOCAL_ACTIVE',
}
}
},
tlsRejectUnauthorized: {
doc: 'Indicates if TLS should reject unauthorized certifates. Never disable in production!',
format: ['0', '1'],
default: '1',
env: 'NODE_TLS_REJECT_UNAUTHORIZED',
},
foreSee: {
src: {
doc: 'The special ForeSee source string to include in the ForeSee javascript snippet.',
format: 'String',
default: '//gateway.foresee.com/sites/[your sitekey]/staging/gateway.min.js',
env: 'FORESEE_SRC',
},
active: {
doc: 'Indicates if ForeSee integration is active',
format: 'Boolean',
default: false,
env: 'FORESEE_ACTIVE',
}
},
terminologyService: {
doc: 'Terminology Service Endpoint URL',
format: 'String',
default: 'https://cts.nlm.nih.gov/fhir',
env: 'TERMINOLOGY_ENDPOINT',
},
});
// Load environment dependent configuration
const files = [];
// Look for an environment-based file (e.g., config/production.json)
const envFile = `./config/${config.get('env')}.json`;
if (fs.existsSync(envFile)) {
files.push(envFile);
}
// Look for a local config file to override config locally (in development)
const localFile = './config/local.json';
if (fs.existsSync(localFile)) {
files.push(localFile);
}
// Load any config files that were found. If no, default value will be used.
if (files.length > 0) {
config.loadFile(files);
}
// Perform validation
config.validate({ allowed: 'strict' });
console.log('Loaded config:', config.toString());
module.exports = config;