about summary refs log tree commit diff stats
path: root/src/index.ts
blob: 30a6f342742324a3db9d7b4defc44986aaeda27d (plain)
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
import { performance } from "node:perf_hooks";

performance.mark("startup-begin");

import log from "loglevel";

import { server, metricsServer } from "./app";

log.setLevel((import.meta.env["LOG_LEVEL"] || "info") as log.LogLevelDesc);

const metricsServed = Bun.serve(metricsServer);
log.info(`Metrics server started on port ${metricsServed.port}`);

const served = Bun.serve(server);
log.info(`Serving website on ${served.url}`);

process.on("SIGTERM", function () {
  log.info("SIGTERM received, shutting down...");
  metricsServed.stop();
  served.stop();
  process.exit(0);
});

process.on("SIGINT", function () {
  log.info("SIGINT received, shutting down...");
  metricsServed.stop();
  served.stop();
  process.exit(0);
});

performance.mark("startup-end");

performance.measure("startup", "startup-begin", "startup-end");
for (const entry of performance.getEntriesByName("startup")) {
  log.info(`Startup took ${entry.duration} ms`);
}