1
1
import { BrowserModule } from '@angular/platform-browser' ;
2
2
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
3
3
import { NgModule , Injector , APP_INITIALIZER , LOCALE_ID } from '@angular/core' ;
4
+ import { PlatformLocation } from '@angular/common' ;
4
5
5
6
import { AbpModule } from '@abp/abp.module' ;
6
7
import { AbpHttpInterceptor } from '@abp/abpHttpInterceptor' ;
@@ -17,69 +18,91 @@ import { API_BASE_URL } from '@shared/service-proxies/service-proxies';
17
18
import { RootComponent } from './root.component' ;
18
19
import { AppPreBootstrap } from './AppPreBootstrap' ;
19
20
import { ModalModule } from 'ngx-bootstrap' ;
20
- import { HttpClientModule , HttpResponse } from '@angular/common/http' ;
21
-
22
- export function appInitializerFactory ( injector : Injector ) {
23
- return ( ) => {
24
-
25
- abp . ui . setBusy ( ) ;
26
- return new Promise < boolean > ( ( resolve , reject ) => {
27
- AppPreBootstrap . run ( ( ) => {
28
- abp . event . trigger ( 'abp.dynamicScriptsInitialized' ) ;
29
- var appSessionService : AppSessionService = injector . get ( AppSessionService ) ;
30
- appSessionService . init ( ) . then (
31
- ( result ) => {
32
- abp . ui . clearBusy ( ) ;
33
- resolve ( result ) ;
34
- } ,
35
- ( err ) => {
36
- abp . ui . clearBusy ( ) ;
37
- reject ( err ) ;
38
- }
39
- ) ;
40
- } ) ;
41
- } ) ;
42
- }
21
+ import { HttpClientModule } from '@angular/common/http' ;
22
+
23
+ export function appInitializerFactory ( injector : Injector ,
24
+ platformLocation : PlatformLocation ) {
25
+ return ( ) => {
26
+
27
+ abp . ui . setBusy ( ) ;
28
+ return new Promise < boolean > ( ( resolve , reject ) => {
29
+ AppConsts . appBaseHref = getBaseHref ( platformLocation ) ;
30
+ let appBaseUrl = getDocumentOrigin ( ) + AppConsts . appBaseHref ;
31
+
32
+ AppPreBootstrap . run ( appBaseUrl , ( ) => {
33
+ abp . event . trigger ( 'abp.dynamicScriptsInitialized' ) ;
34
+ var appSessionService : AppSessionService = injector . get ( AppSessionService ) ;
35
+ appSessionService . init ( ) . then (
36
+ ( result ) => {
37
+ abp . ui . clearBusy ( ) ;
38
+ resolve ( result ) ;
39
+ } ,
40
+ ( err ) => {
41
+ abp . ui . clearBusy ( ) ;
42
+ reject ( err ) ;
43
+ }
44
+ ) ;
45
+ } ) ;
46
+ } ) ;
47
+ }
43
48
}
44
49
45
50
export function getRemoteServiceBaseUrl ( ) : string {
46
- return AppConsts . remoteServiceBaseUrl ;
51
+ return AppConsts . remoteServiceBaseUrl ;
47
52
}
48
53
49
54
export function getCurrentLanguage ( ) : string {
50
55
return abp . localization . currentLanguage . name ;
51
56
}
52
57
53
58
@NgModule ( {
54
- imports : [
55
- BrowserModule ,
56
- BrowserAnimationsModule ,
57
- SharedModule . forRoot ( ) ,
58
- ModalModule . forRoot ( ) ,
59
- AbpModule ,
60
- ServiceProxyModule ,
61
- RootRoutingModule ,
62
- HttpClientModule
63
- ] ,
64
- declarations : [
65
- RootComponent
66
- ] ,
67
- providers : [
68
- { provide : HTTP_INTERCEPTORS , useClass : AbpHttpInterceptor , multi : true } ,
69
- { provide : API_BASE_URL , useFactory : getRemoteServiceBaseUrl } ,
70
- {
71
- provide : APP_INITIALIZER ,
72
- useFactory : appInitializerFactory ,
73
- deps : [ Injector ] ,
74
- multi : true
75
- } ,
76
- {
77
- provide : LOCALE_ID ,
78
- useFactory : getCurrentLanguage
79
- }
80
- ] ,
81
- bootstrap : [ RootComponent ]
59
+ imports : [
60
+ BrowserModule ,
61
+ BrowserAnimationsModule ,
62
+ SharedModule . forRoot ( ) ,
63
+ ModalModule . forRoot ( ) ,
64
+ AbpModule ,
65
+ ServiceProxyModule ,
66
+ RootRoutingModule ,
67
+ HttpClientModule
68
+ ] ,
69
+ declarations : [
70
+ RootComponent
71
+ ] ,
72
+ providers : [
73
+ { provide : HTTP_INTERCEPTORS , useClass : AbpHttpInterceptor , multi : true } ,
74
+ { provide : API_BASE_URL , useFactory : getRemoteServiceBaseUrl } ,
75
+ {
76
+ provide : APP_INITIALIZER ,
77
+ useFactory : appInitializerFactory ,
78
+ deps : [ Injector , PlatformLocation ] ,
79
+ multi : true
80
+ } ,
81
+ {
82
+ provide : LOCALE_ID ,
83
+ useFactory : getCurrentLanguage
84
+ }
85
+ ] ,
86
+ bootstrap : [ RootComponent ]
82
87
} )
88
+
83
89
export class RootModule {
84
90
85
91
}
92
+
93
+ export function getBaseHref ( platformLocation : PlatformLocation ) : string {
94
+ var baseUrl = platformLocation . getBaseHrefFromDOM ( ) ;
95
+ if ( baseUrl ) {
96
+ return baseUrl ;
97
+ }
98
+
99
+ return '/' ;
100
+ }
101
+
102
+ function getDocumentOrigin ( ) {
103
+ if ( ! document . location . origin ) {
104
+ return document . location . protocol + "//" + document . location . hostname + ( document . location . port ? ':' + document . location . port : '' ) ;
105
+ }
106
+
107
+ return document . location . origin ;
108
+ }
0 commit comments