forked from ehacke/ts-di-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.ts
34 lines (27 loc) · 992 Bytes
/
start.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
/* eslint no-process-exit: "off" */
import log from '@/logger';
import Bluebird from 'bluebird';
import * as app from './app';
import ConfigLoader from './configLoader';
import { Server } from './server';
const { ServiceManager } = app;
const startingConfig = ConfigLoader.load();
(async (): Promise<void> => {
const serviceManager = new ServiceManager(startingConfig);
const server = new Server(serviceManager);
// Graceful shutdown from SIGTERM
process.on('SIGTERM', async () => {
log.warn('SIGTERM received stopping server...');
await server.stop();
process.exit(0);
});
process.on('unhandledRejection', (r, p) => {
log.warn('Unhandled rejection at: ', p);
process.exit(1);
});
// This is dumb, but sometimes everything starts before redis has connected
// Rather than tricking ioredis into connecting manually, easier to just wait a bit
// eslint-disable-next-line no-magic-numbers
await Bluebird.delay(500);
await server.start();
})();