forked from ridencww/uniroster-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.js
40 lines (33 loc) · 1.63 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
function getBool(key, defaultValue) {
if (defaultValue == undefined) defaultValue = true;
return process.env[key] ? process.env[key] === "true" : defaultValue;
}
function getInt(key, defaultValue) {
if (defaultValue == undefined) defaultValue = 0;
return process.env[key] ? parseInt(process.env[key], 10) : defaultValue;
}
const db = {};
db.host = process.env.DB_HOSTNAME || 'localhost';
db.user = process.env.DB_USERNAME || 'root';
db.password = process.env.DB_PASSWORD || 'password';
db.connectionLimit = getInt("DB_CONNECTION_LIMIT", 10);
const auth = {};
auth.database = process.env.AUTH_DATABASE || 'accounts';
auth.accessTokenLifetime = getInt(process.env.ACCESS_TOKEN_LIFETIME, 60 * 60 * 24); // default 1 day
auth.enableClientRegistration = getBool("ENABLE_CLIENT_REGISTRATION");
auth.enableClientRemoval = getBool("ENABLE_CLIENT_REMOVAL");
auth.enableInitialNoAuthRegistration = getBool("ENABLE_INITIAL_NO_AUTH_REGISTRATION", false);
auth.enableSettingsEndpoint = getBool("ENABLE_SETTINGS_ENDPOINT");
auth.defaultClientId = process.env.DEFAULT_CLIENT_ID || 'default-client';
auth.defaultClientSecret = process.env.DEFAULT_CLIENT_SECRET || 'default-secret';
auth.defaultDataset = process.env.DEFAULT_DATASET || 'sample_or10';
const config = {};
config.db = db;
config.auth = auth;
config.httpActive = getBool("HTTP_ACTIVE");
config.httpPort = getInt("HTTP_PORT", 80);
config.httpsActive = getBool("HTTPS_ACTIVE", false);
config.httpsPort = getInt("HTTPS_PORT", 443);
config.httpsCert = process.env.HTTPS_CERT || './certs/server.cert';
config.httpsPrivateKey = process.env.HTTPS_PRIVATE_KEY || './certs/server.key';
module.exports = config;