-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathindex.ts
More file actions
47 lines (42 loc) · 1.28 KB
/
index.ts
File metadata and controls
47 lines (42 loc) · 1.28 KB
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
import 'newrelic';
import { SetupServer } from './server';
import logger from './logger';
import config from 'config';
enum ExitStatus {
Failure = 1,
Success = 0,
}
process.on('unhandledRejection', (reason, promise) => {
logger.error(
`App exiting due to an unhandled promise: ${promise} and reason: ${reason}`
);
// lets throw the error and let the uncaughtException handle below handle it
throw reason;
});
process.on('uncaughtException', (error) => {
logger.error(`App exiting due to an uncaught exception: ${error}`);
process.exit(ExitStatus.Failure);
});
(async (): Promise<void> => {
try {
const server = new SetupServer(config.get('App.port'));
await server.init();
server.start();
const exitSignals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGQUIT'];
for (const exitSignal of exitSignals) {
process.on(exitSignal, async () => {
try {
await server.close();
logger.info(`App exited with success`);
process.exit(ExitStatus.Success);
} catch (error) {
logger.error(`App exited with error: ${error}`);
process.exit(ExitStatus.Failure);
}
});
}
} catch (error) {
logger.error(`App exited with error: ${error}`);
process.exit(ExitStatus.Failure);
}
})();