-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (29 loc) · 912 Bytes
/
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
const expressApp = require("./api");
const helmet = require("helmet");
const { createLightship } = require("lightship");
const rateLimiter = require("./src/rateLimit");
const { logger } = require("./src/logging");
const prometheus = require("./src/prometheus");
const PORT = process.env.PORT || 5000;
// Add middleware
prometheus(expressApp); // Add prometheus middleware
expressApp.use(helmet()); // Add helmet middleware
expressApp.use(rateLimiter); // Add rate limiter middleware
// Health check
expressApp.get("/healthz", (_req, res) => {
res.send("OK");
});
// Start the server
const server = expressApp
.listen(PORT, () => {
logger.info(`listening on ${PORT}`);
lightship.signalReady();
})
.on("error", () => {
logger.info(`shutting down server`);
lightship.shutdown();
});
const lightship = createLightship();
lightship.registerShutdownHandler(() => {
server.close();
});