-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathserver.ts
27 lines (22 loc) · 824 Bytes
/
server.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
import { config } from './configuration';
import { appFactory } from './http/app';
import { logger } from './libs/logger';
import { createUserRepository } from './data/users/userRepository';
import { UsersService } from './domain/users/usersService';
import { init } from './signals';
import { Database } from './data/database';
const database = new Database(config.connectionString as string);
database.connect();
const userRepository = createUserRepository();
const userService = new UsersService(userRepository);
const app = appFactory(userService);
const server = app.listen(config.port, () => {
logger.info(`Listening on *:${config.port}`);
});
const shutdown = init(() => {
server.close(async () => {
await database.disconnect();
});
});
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);