-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.ts
43 lines (37 loc) · 1.17 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
import { KitesFactory, KitesInstance } from '@kites/core';
import { UserService, User } from './api';
import mongoose from 'mongoose';
import { GetDbConnection, AppRoutes, MediaServer } from './extensions';
async function bootstrap() {
const app = await KitesFactory
.create({
loadConfig: true,
discover: true,
providers: [
UserService,
// TextService,
],
})
.use(AppRoutes)
.use(MediaServer)
.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 });
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();