-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
core.module.ts
99 lines (95 loc) · 3.33 KB
/
core.module.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { APP_INITIALIZER, NgModule, Optional, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { FormlyModule } from '@ngx-formly/core';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { NgxsModule } from '@ngxs/store';
import { NgxsFormPluginModule } from '@ngxs/form-plugin';
import { NgxPageScrollModule } from 'ngx-page-scroll';
import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin';
import { NgxsRouterPluginModule, RouterStateSerializer } from '@ngxs/router-plugin';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faTwitter, faGithub, faGoogle } from '@fortawesome/free-brands-svg-icons';
import { AuthModule, AuthState } from '@ngx-starter-kit/auth';
import { NavigatorModule, MenuState } from '@ngx-starter-kit/navigator';
import { NgxsWebsocketPluginModule } from '@ngx-starter-kit/socketio-plugin';
import { environment } from '@env/environment';
import { EventBus } from './state/eventbus';
import { defaultMenu, demoMenu, adminMenu } from './menu-data';
import { PreferenceState } from './state/preference.state';
import { InMemoryDataService } from './services/in-memory-data.service';
import { ErrorInterceptor } from './interceptors/error.interceptor';
import { JwtInterceptor } from './interceptors/jwt.interceptor';
import { CustomRouterStateSerializer } from './state/custom-router-state.serializer';
// Noop handler for factory function
export function noop() {
return function() {};
}
/**
* add icons that are needed during app boot up here.
* if more icons are needed, load them in respective modules and add FontAwesomeModule to it.
* for convenience, we also added FontAwesomeModule to SharedModule.
*/
library.add(faTwitter, faGithub, faGoogle);
@NgModule({
imports: [
CommonModule,
HttpClientModule,
FontAwesomeModule,
NgxPageScrollModule,
NavigatorModule.forRoot(defaultMenu),
NgxsModule.forRoot([AuthState, MenuState, PreferenceState]),
NgxsReduxDevtoolsPluginModule.forRoot({
disabled: environment.production, // Set to true for prod mode
maxAge: 10,
}),
NgxsFormPluginModule.forRoot(),
NgxsWebsocketPluginModule.forRoot({
url: environment.WS_EVENT_BUS_URL,
}),
NgxsRouterPluginModule.forRoot(),
AuthModule.forRoot(),
FormlyModule.forRoot(),
environment.envName === 'mock'
? HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService, {
passThruUnknownUrl: true,
// delay: 500,
// apiBase: 'api'
})
: [],
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: ErrorInterceptor,
multi: true,
},
// {
// provide: HTTP_INTERCEPTORS,
// useClass: JwtInterceptor,
// multi: true,
// },
{
provide: APP_INITIALIZER,
useFactory: noop,
deps: [EventBus],
multi: true,
},
{
provide: RouterStateSerializer,
useClass: CustomRouterStateSerializer,
},
],
})
export class CoreModule {
constructor(
@Optional()
@SkipSelf()
parentModule: CoreModule,
) {
if (parentModule) {
throw new Error('CoreModule is already loaded. Import it in the AppModule only');
}
}
}