-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.js
64 lines (56 loc) · 2.17 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
/* eslint-env node */
const fs = require('fs');
let dependencies = {};
try {
dependencies = JSON.parse(fs.readFileSync('dependencies/dependencies.json', 'utf8'));
} catch (e) {
console.error('Error reading dependencies/dependencies.json! The server will be crippled.');
console.error('Please run python3 dependencies/build.py to generate.');
console.error(e);
}
const serviceAccountKeyString = process.env.FIREBASE_SERVICE_ACCOUNT_KEY_STRING;
const serviceAccountKeyFile = process.env.FIREBASE_SERVICE_ACCOUNT_KEY_FILE;
let serviceAccountKey;
if (serviceAccountKeyString) {
serviceAccountKey = JSON.parse(serviceAccountKeyString);
} else if (serviceAccountKeyFile) {
serviceAccountKey = JSON.parse(fs.readFileSync(serviceAccountKeyFile, 'utf8'));
} else {
throw new Error('FIREBASE_SERVICE_ACCOUNT_KEY_STRING or FIREBASE_SERVICE_ACCOUNT_KEY_FILE must be set');
}
module.exports = {
get: () => {
return {
server: {
port: getEnvVarOrDefault('SERVER_PORT', 3000),
feedbackWebhookURL: getEnvVarOrDefault('FEEDBACK_WEBHOOK_URL', ''),
dependencies
},
caching: {
staticMaxAge: getEnvVarOrDefault('CACHING_STATIC_MAX_AGE', 60 * 60 * 1000),
},
dbUrl: getEnvVarOrDefault('API_URL', 'https://db-prerelease.botballacademy.org'),
firebase: {
// Firebase API keys are not secret, so the real value is okay to keep in code
apiKey: getEnvVarOrDefault('FIREBASE_API_KEY', 'AIzaSyBiVC6umtYRy-aQqDUBv8Nn1txWLssix04'),
serviceAccountKey,
},
mailgun: {
// Provide defaults so mailgun client can be created even if not configured during local development
apiKey: getEnvVarOrDefault('MAILGUN_API_KEY', '<invalid>'),
domain: getEnvVarOrDefault('MAILGUN_DOMAIN', '<invalid>'),
},
};
},
};
function getEnvVarOrDefault(variableName, defaultValue) {
return process.env[variableName] !== undefined
? process.env[variableName]
: defaultValue;
}
// function getEnvVarOrThrow(variableName) {
// if (process.env[variableName] === undefined) {
// throw new Error(`Required environment variable is not set: ${variableName}`);
// }
// return process.env[variableName];
// }