-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
61 lines (49 loc) · 1.52 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
const path = require("path");
const pkg = require("./package.json");
console.log(`Starting Connector v${pkg.version}...`);
// 1) fetch devices from backend
// 2) buld mapping interface ws endpoint to interface obj (tcp/udp/raw socket)
// 2) Try to connect to socket
// 3) if conneciton not possible, try again when data from ws arrives
let env = {};
try {
env = require("dotenv").config({
path: path.resolve(process.cwd(), ".env")
});
if (env.error) {
env.parsed = {};
}
} catch (err) {
//console.log("Could not load dotenv", err.message);
}
// default environment variables
process.env = Object.assign({
NODE_ENV: "production",
BACKEND_URL: "",
BACKEND_PROTOCOL: "http",
BACKEND_HOST: "127.0.0.1",
BACKEND_PORT: "8080",
RECONNECT_DELAY: "15",
ENABLE_SSDP: "true",
ENABLE_MDNS: "true",
ALLOW_HALF_OPEN: "true",
AUTOCONNECT: "true",
STARTUP_DELAY: "0",
MQTT_HOST: "127.0.0.1",
MQTT_PORT: "1883",
ENABLE_MQTT: "false",
LOG_PATH: path.resolve(process.cwd(), "logs"),
LOG_LEVEL: "info",
LOG_DATEFORMAT: "yyyy.mm.dd - HH:MM.ss.l",
LOG_SUPPRESS: "false",
LOG_TARGET: "",
AUTH_TOKEN: ""
}, env.parsed, process.env);
// build backend url if its empty
if (process.env.BACKEND_URL === "") {
process.env.BACKEND_URL = `${process.env.BACKEND_PROTOCOL}://`;
process.env.BACKEND_URL += `${process.env.BACKEND_HOST}:${process.env.BACKEND_PORT}`;
}
setTimeout(() => {
require("./bootstrap.js");
}, Number(process.env.STARTUP_DELAY));