-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (38 loc) · 1.18 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
const express = require("express");
const methodOverride = require("method-override");
const cookieParser = require("cookie-parser");
// const sha256 = require("js-sha256");
// Init express app
const app = express();
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.use(express.static("public"));
// reads the cookies
app.use(cookieParser());
app.use(methodOverride("_method"));
// Set react-views to be the default view engine
const reactEngine = require("express-react-views").createEngine();
app.set("views", __dirname + "/views");
app.set("view engine", "jsx");
app.engine("jsx", reactEngine);
const allModels = require("./db");
const setRoutesFunction = require("./routes");
setRoutesFunction(app, allModels);
// LISTENING TO SERVER
const PORT = process.env.PORT || 3000;
const server = app.listen(PORT, () =>
console.log("~~~ Tuning in to the waves of port " + PORT + " ~~~")
);
let onClose = function () {
console.log("closing");
server.close(() => {
console.log("Process terminated");
allModels.pool.end(() => console.log("Shut down db connection pool"));
});
};
process.on("SIGTERM", onClose);
process.on("SIGINT", onClose);