-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (58 loc) · 1.61 KB
/
index.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
/**
* Server Configuration Script
*/
"use strict";
var nconf = (module.exports = require("nconf"));
var path = require("path");
nconf
// Command-line arguments
.argv()
// Environment variables
.env(["DATA_BACKEND", "MONGO_URL", "MONGO_COLLECTION", "PORT"])
.file({
file: path.join(__dirname, "config.json"),
})
// Defaults
.defaults({
LOG_LEVEL: "trace",
LOG_FILE: "debug_messages.log",
CORS: true,
ALLOW_AUTODATAHANDLER: true,
// dataBackend can be 'datastore', 'cloudsql', or 'mongodb'. Be sure to
// configure the appropriate settings for each storage engine below.
// If you are unsure, use datastore as it requires no additional
// configuration.
DATA_BACKEND: "mongodb",
// MongoDB connection string
MONGO_URL: "your-mongo-host",
MONGO_COLLECTION: "your-db",
MAX_FIELD_IN_HTTP_REQ: 100,
// Default Port the HTTP/HTTPS server
PORT: 8080,
HTTPS_PORT: 443,
// Default Port the HTTP server
TEST_PORT: 8186,
TEST_HTTPS_PORT: 44186, //for ssl
// Processing interval in seconds
PROCESSING_INTERVAL: 2,
});
// Check for required settings
checkConfig("DATA_BACKEND");
if (nconf.get("DATA_BACKEND") === "cloudsql") {
checkConfig("MYSQL_USER");
checkConfig("MYSQL_PASSWORD");
checkConfig("MYSQL_HOST");
} else if (nconf.get("DATA_BACKEND") === "mongodb") {
checkConfig("MONGO_URL");
checkConfig("MONGO_COLLECTION");
}
function checkConfig(setting) {
if (!nconf.get(setting)) {
throw new Error(
"You must set the " +
setting +
" environment variable or" +
" add it to config.json!"
);
}
}