-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunserver.ts
More file actions
43 lines (38 loc) · 1.08 KB
/
Copy pathrunserver.ts
File metadata and controls
43 lines (38 loc) · 1.08 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
import server from './src/server';
import log from './src/log';
import cfg, { logConfiguration } from './src/configuration';
import * as db from './src/database/db';
import * as Sentry from '@sentry/node';
import { extractErrorMessage } from './src/errors';
async function startup() {
logConfiguration();
try {
await db.checkConnection();
await db.checkMigrations();
} catch (err) {
const errMsg = extractErrorMessage(err);
log.error(`Could not ensure database connection / migrations: '${errMsg}'`);
log.warn("Will try again on first request");
Sentry.captureException(err);
}
server.listen(cfg.API_PORT, () => {
log.info(`Server started, awaiting connections on port ${cfg.API_PORT}`);
});
}
process.on('SIGINT', () => {
shutdown('SIGINT');
});
process.on('SIGTERM', () => {
shutdown('SIGTERM');
});
function shutdown(reason: string) {
log.info(`Server exiting: ${reason}`);
db.shutdown().finally(() => {
log.info('Goodbye!');
process.exit()
});
}
startup().catch((err) => {
log.error(`Error on startup: ${extractErrorMessage(err)}`);
Sentry.captureException(err);
});