-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
33 lines (27 loc) · 925 Bytes
/
app.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
import { Event } from './elements/Event';
import { EventPublisher } from './publishers/EventPublisher';
import { EventStore } from './stores/EventStore';
import { flaschenpost } from 'flaschenpost';
import { getApi } from './apis/getApi';
import http from 'http';
import { processenv } from 'processenv';
import { runProjections } from './projections/runProjections';
import { ViewStore } from './stores/ViewStore';
const logger = flaschenpost.getLogger();
const eventStore = new EventStore();
const eventPublisher = new EventPublisher();
const viewStore = new ViewStore();
eventPublisher.on('domain-event', ({ event }: {
event: Event;
}): void => {
runProjections({ viewStore, event });
});
const server = http.createServer(getApi({
eventStore,
eventPublisher,
viewStore
}));
const port = processenv('PORT', 3_000) as number;
server.listen(port, (): void => {
logger.info('Server started.', { port });
});