-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (36 loc) · 1.14 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
const passport = require("koa-passport");
const log = require("./helpers/log");
const { app, createServer, start, addRoutes, shutdown } = require("./web");
const { connect: connectDB } = require("./db");
const config = require("./config");
const actions = require("./actions");
const { port } = config;
process.on("unhandledRejection", (reason, p) => {
log("error", "Unhandled Rejection at: Promise", p, "reason:", reason);
process.exit(1);
});
process.on("uncaughtException", (err) => {
log("error", "Uncaught Exception:", err);
process.exit(1);
});
(async () => {
// test DB connection and return it to pool
try {
await connectDB(() => null);
} catch (err) {
log("error", "Can't connect to DB", err);
process.exit(1);
}
const server = await createServer();
process.on("SIGINT", () => {
log("info", "Got SIGINT (aka ctrl-c in docker). Graceful shutdown ");
shutdown(server);
});
process.on("SIGTERM", () => {
log("info", "Got SIGTERM (docker container stop). Graceful shutdown ");
shutdown(server);
});
app.use(passport.initialize());
addRoutes(actions, "./client");
start(server, port);
})();