-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (63 loc) · 1.83 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
69
70
71
72
73
const fs = require("fs");
const winston = require("winston");
const path = require("path");
const server = require("./src/server");
const logLevel = process.env.SIGN_LOGLEVEL || "debug";
const serverPort = process.env.SIGN_PORT || 3000;
const serverHost = process.env.SIGN_HOST || "127.0.0.1";
const authControllerToken =
process.env.SIGN_CONTROLLER_SECRET || "controllerchangeme";
const authStaffToken = process.env.SIGN_STAFF_SECRET || "staffchangeme";
const nodeEnv = process.env.NODE_ENV || "development";
const { version } = JSON.parse(
fs.readFileSync(path.join(__dirname, "package.json"), "utf8"),
);
// configure the logger
const log = winston.createLogger({
format: winston.format.combine(
winston.format.splat(),
winston.format.timestamp(),
winston.format.errors({ stack: true }),
winston.format.printf(
(info) => `${info.timestamp} ${info.level}: ${info.message}`,
),
),
transports: [
new winston.transports.Console({
level: logLevel,
}),
],
});
// set up error handling
process.on("uncaughtException", (err) => {
log.error("Uncaught exception!", err);
process.exit(1);
});
process.on("unhandledRejection", (err) => {
log.error("Uncaught promise rejection!", err);
process.exit(1);
});
// handle shutdown requests gracefully
process.on("SIGTERM", () => {
log.info("Received SIGTERM, shutting down.");
process.exit(0);
});
process.on("SIGINT", () => {
log.info("Received SIGINT, shutting down.");
process.exit(0);
});
const app = server(log, authControllerToken, authStaffToken).listen(
serverPort,
serverHost,
() => {
const { port, address: host } = app.address();
log.info(
"I Saw The Sign (and it opened up my eyes) Server v%s (%s) listening at http://%s:%s (Node.js %s)",
version,
nodeEnv,
host,
port,
process.version,
);
},
);