-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathmain.ts
38 lines (34 loc) · 1.13 KB
/
main.ts
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
import { Express } from "express";
import "config/env"; // Important to be before other dependencies
import { getLogger } from "config/logger";
import throng from "throng";
import { initializeSentry } from "config/sentry";
import { isNodeProd } from "utils/is-node-env";
import { getFrontendApp } from "./app";
import createLag from "event-loop-lag";
import { initStatsdLogger, statsd } from "config/statsd";
import { metricPerf } from "config/metric-names";
const start = async () => {
initStatsdLogger(getLogger("config.statsd"));
initializeSentry();
const app: Express = getFrontendApp();
const port = Number(process.env.TUNNEL_PORT) || Number(process.env.PORT) || 8080;
app.listen(port, () => {
getLogger("frontend-app").info(`started at port ${port}`);
});
const lag = createLag(1000);
setInterval(() => {
statsd.histogram(metricPerf.lagHist, lag(), { }, { });
}, 1000);
};
if (isNodeProd()) {
// Production clustering (one process per core)
throng({
worker: start,
lifetime: Infinity
});
} else {
// Dev/test single process, don't need clustering
// eslint-disable-next-line @typescript-eslint/no-floating-promises
start();
}