-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathbootstrap.ts
38 lines (32 loc) · 1.13 KB
/
bootstrap.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
import 'reflect-metadata';
import { InversifyExpressServer } from 'inversify-express-utils';
import { Container } from 'inversify';
import { makeLoggerMiddleware } from 'inversify-logger-middleware';
import * as bodyParser from 'body-parser';
import * as helmet from 'helmet';
import TYPES from './constant/types';
import { UserService } from './service/user';
import { MongoDBClient } from './utils/mongodb/client';
import './controller/home';
import './controller/user';
// load everything needed to the Container
let container = new Container();
if (process.env.NODE_ENV === 'development') {
let logger = makeLoggerMiddleware();
container.applyMiddleware(logger);
}
container.bind<MongoDBClient>(TYPES.MongoDBClient).to(MongoDBClient);
container.bind<UserService>(TYPES.UserService).to(UserService);
// start the server
let server = new InversifyExpressServer(container);
server.setConfig((app) => {
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(helmet());
});
let app = server.build();
app.listen(3000);
console.log('Server started on port 3000 :)');
exports = module.exports = app;