forked from meepobrother/nger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
44 lines (43 loc) · 1.48 KB
/
server.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
import { NgModule, OnInit, Inject, OnError, DevModelToken, Logger } from 'nger-core';
import { HomeController, UserController, SmsController } from './inc';
import { NgerModuleTypeorm } from 'nger-module-typeorm'
import { NgerRunnerTypeorm } from './typeorm';
import { StoreModule } from 'nger-store';
import { counterReducer } from './store/counter.reducer'
import { CounterEffects } from './store/counter.effects'
import { EffectsModule } from 'nger-effects';
import { Injector } from 'nger-di';
/** api服务 */
@NgModule({
declarations: [
HomeController,
UserController,
SmsController
],
providers: [{
provide: DevModelToken,
useValue: true
}],
imports: [
NgerModuleTypeorm.forRoot(NgerRunnerTypeorm),
StoreModule.forRoot({ count: counterReducer }),
EffectsModule.forRoot([CounterEffects])
]
})
export default class NgerServer implements OnInit, OnError {
// 只能获取全局注入对象
@Inject() public logger: Logger;
@Inject() public home: HomeController;
@Inject() public injector: Injector;
// 暂不支持在构造函数中获取
constructor() { }
ngOnInit() {
this.logger.info(`NgerServer on init!! and inject the HomeController ${this.home.info.username}`);
}
// server 端捕获错误
ngOnError(err: Error) {
// this.injector.debug();
this.logger.error(`ngOnError`, err.message)
this.logger.error(`ngOnError:detail ${err.stack}`)
}
}