-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstartServer.ts
52 lines (47 loc) · 1.42 KB
/
startServer.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { AppConfig } from "../config/bootstrap/appConfig";
import { createApp } from "../config/bootstrap/server";
import { createLogger } from "../utils/logger";
import {
startPeriodicNodeProcessReport,
startSamplingEventLoopLag,
} from "../utils/nodeProcessReport";
import { configureSentry } from "./configureSentry";
const logger = createLogger(__filename);
const getPort = (): number => {
if (!process.env.PORT) return 1234;
return parseInt(process.env.PORT);
};
const appConfig = AppConfig.createFromEnv();
createApp(appConfig).then(
({ app, gateways }) => {
const port = getPort();
app.listen(port, "0.0.0.0", () => {
logger.info({ message: `server started at http://localhost:${port}` });
const intervalMs = appConfig.nodeProcessReportInterval;
const eventLoopSamples: number[] = [];
const maxSampleSize = Math.max(
5,
Math.min(1000, Math.ceil(intervalMs / 50)),
);
startSamplingEventLoopLag(
eventLoopSamples,
maxSampleSize,
Math.floor(intervalMs / maxSampleSize),
logger,
);
startPeriodicNodeProcessReport(
intervalMs,
gateways.timeGateway,
logger,
eventLoopSamples,
maxSampleSize,
);
});
configureSentry(appConfig);
},
(error: any) => {
logger.error({ message: `Server start failed, ${error.message}`, error });
console.error(error);
process.exit(1);
},
);