-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
59 lines (46 loc) · 1.53 KB
/
server.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
const express = require('express');
const server = express();
const path = require("path");
const {createProxyMiddleware} = require('http-proxy-middleware');
const builddirectory = path.join(__dirname, 'dist');
server.set("keepAliveTimeout", 61 * 1000);
server.set("headersTimeout", 65 * 1000);
server.use(express.static(path.join(__dirname, 'dist')));
server.get('/', function (req, res) {
res.render(path.join(builddirectory, 'index.html'));
});
server.get('/health', function (req, res) {
res.send({status: "ok"})
});
server.get('/api/secrets', function (req, res) {
res.send({PAGE_TITLE: process.env.PAGE_TITLE})
});
server.use("/api/review", createProxyMiddleware({
changeOrigin: true,
secure: true,
target: process.env.REVIEW_API,
logLevel: "info",
}));
const serverInstance = server.listen(4200, () => {
console.log(`Server is up ...`);
});
let connections = [];
server.on("connection", (connection) => {
connections.push(connection);
connection.on("close", () => (connections = connections.filter((curr) => curr !== connection)));
});
const shutDown = () => {
console.log("Shutting down...");
serverInstance.close(() => {
console.log("Closed out remaining connections");
process.exit(0);
});
setTimeout(() => {
console.error("Could not close connections in time, Force shutting down...");
process.exit(1);
}, 10000);
connections.forEach((curr) => curr.end());
setTimeout(() => connections.forEach((curr) => curr.destroy()), 5000);
};
process.on("SIGTERM", shutDown);
process.on("SIGINT", shutDown);