@@ -794,10 +794,62 @@ describe('platform-server integration', () => {
794
794
} ) ) ;
795
795
796
796
describe ( 'relative requests' , ( ) => {
797
+ it ( 'will throw if "useAbsoluteUrl" is true but "baseUrl" is not provided' , async ( ) => {
798
+ const platform = platformDynamicServer ( [ {
799
+ provide : INITIAL_CONFIG ,
800
+ useValue : {
801
+ document : '<app></app>' ,
802
+ url : 'http://localhost' ,
803
+ useAbsoluteUrl : true ,
804
+ } ,
805
+ } ] ) ;
806
+ const appRef = await platform . bootstrapModule ( HttpClientExampleModule ) ;
807
+ expect ( ( ) => appRef . injector . get ( PlatformLocation ) )
808
+ . toThrowError ( / " P l a t f o r m C o n f i g \. b a s e U r l " m u s t b e s e t i f " u s e A b s o l u t e U r l " i s t r u e / ) ;
809
+ } ) ;
810
+
811
+ it ( 'will resolve absolute url using "baseUrl"' , async ( ) => {
812
+ const platform = platformDynamicServer ( [ {
813
+ provide : INITIAL_CONFIG ,
814
+ useValue : {
815
+ document : '<app></app>' ,
816
+ url : 'http://localhost' ,
817
+ useAbsoluteUrl : true ,
818
+ baseUrl : 'https://angular.io:8080' ,
819
+ } ,
820
+ } ] ) ;
821
+ const appRef = await platform . bootstrapModule ( HttpClientExampleModule ) ;
822
+ const location = appRef . injector . get ( PlatformLocation ) ;
823
+ expect ( location . protocol ) . toBe ( 'https:' ) ;
824
+ expect ( location . hostname ) . toBe ( 'angular.io' ) ;
825
+ expect ( location . port ) . toBe ( '8080' ) ;
826
+ } ) ;
827
+
828
+ it ( '"baseUrl" has no effect if "useAbsoluteUrl" is not enabled' , async ( ) => {
829
+ const platform = platformDynamicServer ( [ {
830
+ provide : INITIAL_CONFIG ,
831
+ useValue : {
832
+ document : '<app></app>' ,
833
+ url : 'http://localhost' ,
834
+ baseUrl : 'https://angular.io:8080' ,
835
+ } ,
836
+ } ] ) ;
837
+ const appRef = await platform . bootstrapModule ( HttpClientExampleModule ) ;
838
+ const location = appRef . injector . get ( PlatformLocation ) ;
839
+ expect ( location . protocol ) . toBe ( 'http:' ) ;
840
+ expect ( location . hostname ) . toBe ( 'localhost' ) ;
841
+ expect ( location . port ) . toBe ( '' ) ;
842
+ } ) ;
843
+
797
844
it ( 'correctly maps to absolute URL request with base config' , async ( ) => {
798
845
const platform = platformDynamicServer ( [ {
799
846
provide : INITIAL_CONFIG ,
800
- useValue : { document : '<app></app>' , url : 'http://localhost' , useAbsoluteUrl : true }
847
+ useValue : {
848
+ document : '<app></app>' ,
849
+ url : 'http://localhost' ,
850
+ baseUrl : 'http://localhost' ,
851
+ useAbsoluteUrl : true ,
852
+ }
801
853
} ] ) ;
802
854
const ref = await platform . bootstrapModule ( HttpClientExampleModule ) ;
803
855
const mock = ref . injector . get ( HttpTestingController ) as HttpTestingController ;
@@ -831,7 +883,12 @@ describe('platform-server integration', () => {
831
883
it ( 'correctly maps to absolute URL request with port' , async ( ) => {
832
884
const platform = platformDynamicServer ( [ {
833
885
provide : INITIAL_CONFIG ,
834
- useValue : { document : '<app></app>' , url : 'http://localhost:5000' , useAbsoluteUrl : true }
886
+ useValue : {
887
+ document : '<app></app>' ,
888
+ url : 'http://localhost:5000' ,
889
+ baseUrl : 'http://localhost' ,
890
+ useAbsoluteUrl : true ,
891
+ }
835
892
} ] ) ;
836
893
const ref = await platform . bootstrapModule ( HttpClientExampleModule ) ;
837
894
const mock = ref . injector . get ( HttpTestingController ) as HttpTestingController ;
@@ -848,7 +905,12 @@ describe('platform-server integration', () => {
848
905
it ( 'correctly maps to absolute URL request with two slashes' , async ( ) => {
849
906
const platform = platformDynamicServer ( [ {
850
907
provide : INITIAL_CONFIG ,
851
- useValue : { document : '<app></app>' , url : 'http://localhost/' , useAbsoluteUrl : true }
908
+ useValue : {
909
+ document : '<app></app>' ,
910
+ url : 'http://localhost/' ,
911
+ baseUrl : 'http://localhost' ,
912
+ useAbsoluteUrl : true ,
913
+ }
852
914
} ] ) ;
853
915
const ref = await platform . bootstrapModule ( HttpClientExampleModule ) ;
854
916
const mock = ref . injector . get ( HttpTestingController ) as HttpTestingController ;
@@ -865,7 +927,12 @@ describe('platform-server integration', () => {
865
927
it ( 'correctly maps to absolute URL request with no slashes' , async ( ) => {
866
928
const platform = platformDynamicServer ( [ {
867
929
provide : INITIAL_CONFIG ,
868
- useValue : { document : '<app></app>' , url : 'http://localhost' , useAbsoluteUrl : true }
930
+ useValue : {
931
+ document : '<app></app>' ,
932
+ url : 'http://localhost' ,
933
+ baseUrl : 'http://localhost' ,
934
+ useAbsoluteUrl : true ,
935
+ }
869
936
} ] ) ;
870
937
const ref = await platform . bootstrapModule ( HttpClientExampleModule ) ;
871
938
const mock = ref . injector . get ( HttpTestingController ) as HttpTestingController ;
@@ -882,8 +949,12 @@ describe('platform-server integration', () => {
882
949
it ( 'correctly maps to absolute URL request with longer url and no slashes' , async ( ) => {
883
950
const platform = platformDynamicServer ( [ {
884
951
provide : INITIAL_CONFIG ,
885
- useValue :
886
- { document : '<app></app>' , url : 'http://localhost/path/page' , useAbsoluteUrl : true }
952
+ useValue : {
953
+ document : '<app></app>' ,
954
+ url : 'http://localhost/path/page' ,
955
+ baseUrl : 'http://localhost' ,
956
+ useAbsoluteUrl : true ,
957
+ }
887
958
} ] ) ;
888
959
const ref = await platform . bootstrapModule ( HttpClientExampleModule ) ;
889
960
const mock = ref . injector . get ( HttpTestingController ) as HttpTestingController ;
@@ -900,8 +971,12 @@ describe('platform-server integration', () => {
900
971
it ( 'correctly maps to absolute URL request with longer url and slashes' , async ( ) => {
901
972
const platform = platformDynamicServer ( [ {
902
973
provide : INITIAL_CONFIG ,
903
- useValue :
904
- { document : '<app></app>' , url : 'http://localhost/path/page' , useAbsoluteUrl : true }
974
+ useValue : {
975
+ document : '<app></app>' ,
976
+ url : 'http://localhost/path/page' ,
977
+ baseUrl : 'http://localhost' ,
978
+ useAbsoluteUrl : true ,
979
+ }
905
980
} ] ) ;
906
981
const ref = await platform . bootstrapModule ( HttpClientExampleModule ) ;
907
982
const mock = ref . injector . get ( HttpTestingController ) as HttpTestingController ;
@@ -922,7 +997,8 @@ describe('platform-server integration', () => {
922
997
useValue : {
923
998
document : '<base href="http://other"><app></app>' ,
924
999
url : 'http://localhost/path/page' ,
925
- useAbsoluteUrl : true
1000
+ baseUrl : 'http://localhost' ,
1001
+ useAbsoluteUrl : true ,
926
1002
}
927
1003
} ] ) ;
928
1004
const ref = await platform . bootstrapModule ( HttpClientExampleModule ) ;
0 commit comments