-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.ts
56 lines (49 loc) · 1.37 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'reflect-metadata'; // this shim is required
import { createExpressServer, useContainer as routingUseContainer } from 'routing-controllers';
import { createConnection, useContainer as ormUseContainer } from 'typeorm';
import { Container } from 'typedi';
import { models as entities } from './models';
import { Config } from './config';
import { InMemoryDatabaseCache } from './utils/InMemoryDatabaseCache';
import { logger as log } from './utils/Logger';
import { controllers } from './api/controllers';
import { middlewares } from './api/middleware';
routingUseContainer(Container);
ormUseContainer(Container);
createConnection({
type: 'postgres',
host: Config.database.host,
port: Config.database.port,
username: Config.database.user,
password: Config.database.pass,
database: Config.database.name,
entities,
logging: Config.isDevelopment,
cache: {
provider(_connection) {
return new InMemoryDatabaseCache();
},
},
}).then(() => {
log.info('created connection');
}).catch((error) => {
log.error(error);
});
const app = createExpressServer({
cors: true,
routePrefix: '/api/v2',
controllers,
middlewares,
defaults: {
paramOptions: {
required: true,
},
},
validation: {
whitelist: true,
skipMissingProperties: true,
forbidUnknownValues: true,
},
defaultErrorHandler: false,
});
app.listen(Config.port);