-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (39 loc) · 1.07 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
const polka = require("polka");
const sirv = require("sirv");
const compression = require("compression");
const cors = require("cors");
const helmet = require("helmet");
const { createLightship } = require("lightship");
/**
* Initial environment variables
*/
const { PORT = 3000, BUILD_PATH, ENABLE_GZIP } = process.env;
const corsConfigs = require("./configs/cors");
const helmetConfigs = require("./configs/helmet");
const app = polka();
const serve = sirv(BUILD_PATH, { single: true });
/**
* Setup app middlewares
*/
ENABLE_GZIP === "true" && app.use(compression());
app
.use(cors(corsConfigs))
.use(
helmet({
referrerPolicy: { policy: helmetConfigs.referrerPolicy },
contentSecurityPolicy: helmetConfigs.enableCsp && helmetConfigs.csp,
})
)
.use(serve)
.listen(PORT, (err) => {
if (err) throw err;
console.log(`Server is ready at http://localhost:${PORT}`);
});
/**
* Setup Lightship for Kubernetes
*/
const lightship = createLightship();
lightship.registerShutdownHandler(() => {
app.server.close();
});
lightship.signalReady();