forked from hsdt/checkin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
53 lines (47 loc) · 1.48 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { KitesFactory, KitesInstance } from '@kites/core';
import mongoose from 'mongoose';
import { UserService, User, TodoService, DMBangMaService, UtilService, CMLoaiTuDienService, CMTuDienService } from './api';
import { GetDbConnection, AppRoutes } from './extensions';
import pkg from './package.json';
async function bootstrap() {
const app = await KitesFactory
.create({
loadConfig: true,
discover: true,
providers: [
TodoService,
UserService,
UtilService,
CMLoaiTuDienService,
CMTuDienService,
DMBangMaService,
],
version: pkg.version,
})
.use(AppRoutes)
.use(GetDbConnection)
.on('db:connect', async (uri: string, kites: KitesInstance) => {
if (typeof uri === 'undefined') {
kites.logger.error('Please config mongodb connection!!!');
return;
}
mongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true,
});
kites.logger.info('Mongodb connect ok: ' + uri);
if (kites.options.env === 'development') {
const vUser = new User();
vUser.username = 'admin';
vUser.password = 'admin';
const svUser = kites.container.inject(UserService);
await svUser.create(vUser);
kites.logger.info('Add default admin(todo:hash) user for testing!');
}
})
.init();
app.logger.info(`Server started!`);
}
bootstrap();