@@ -11,86 +11,58 @@ import { Compiler, CompilerFactory, NgModuleFactory, StaticProvider, Type } from
11
11
import { platformDynamicServer } from '@angular/platform-server' ;
12
12
13
13
import { ORIGIN_URL , REQUEST } from '@nguniversal/aspnetcore-engine/tokens' ;
14
- import { FileLoader } from './file-loader ' ;
14
+ import { ɵFileLoader } from '@nguniversal/common/engine ' ;
15
15
import { IEngineOptions } from './interfaces/engine-options' ;
16
16
import { IEngineRenderResult } from './interfaces/engine-render-result' ;
17
17
import { renderModuleFactory } from './platform-server-utils' ;
18
18
19
- /* @internal */
20
- export class UniversalData {
21
- appNode = '' ;
22
- title = '' ;
23
- scripts = '' ;
24
- styles = '' ;
25
- meta = '' ;
26
- links = '' ;
27
- }
28
-
29
19
/* @internal */
30
20
let appSelector = 'app-root' ; // default
31
21
32
22
/* @internal */
33
- function _getUniversalData ( doc : Document ) : UniversalData {
23
+ function _getUniversalData ( doc : Document ) : Omit < IEngineRenderResult , 'moduleRef' > {
34
24
35
- const STYLES : string [ ] = [ ] ;
36
- const SCRIPTS : string [ ] = [ ] ;
37
- const META : string [ ] = [ ] ;
38
- const LINKS : string [ ] = [ ] ;
25
+ const styles : string [ ] = [ ] ;
26
+ const scripts : string [ ] = [ ] ;
27
+ const meta : string [ ] = [ ] ;
28
+ const links : string [ ] = [ ] ;
39
29
40
- // tslint:disable-next-line: no-non-null-assertion
41
- for ( let i = 0 ; i < doc . head ! . children . length ; i ++ ) {
42
- // tslint:disable-next-line: no-non-null-assertion
43
- const element = doc . head ! . children [ i ] ;
44
- const tagName = element . tagName . toUpperCase ( ) ;
45
-
46
- switch ( tagName ) {
47
- case 'SCRIPT' :
48
- SCRIPTS . push ( element . outerHTML ) ;
49
- break ;
50
- case 'STYLE' :
51
- STYLES . push ( element . outerHTML ) ;
52
- break ;
53
- case 'LINK' :
54
- LINKS . push ( element . outerHTML ) ;
55
- break ;
56
- case 'META' :
57
- META . push ( element . outerHTML ) ;
58
- break ;
59
- default :
60
- break ;
61
- }
62
- }
63
-
64
- for ( let i = 0 ; i < doc . body . children . length ; i ++ ) {
65
- const element : Element = doc . body . children [ i ] ;
66
- const tagName = element . tagName . toUpperCase ( ) ;
30
+ // tslint:disable: no-non-null-assertion
31
+ const elements = [
32
+ ...Array . from ( doc . head ! . children ) ,
33
+ ...Array . from ( doc . body ! . children ) ,
34
+ ] ;
35
+ // tslint:enable: no-non-null-assertion
67
36
68
- switch ( tagName ) {
37
+ for ( const element of elements ) {
38
+ switch ( element . tagName . toUpperCase ( ) ) {
69
39
case 'SCRIPT' :
70
- SCRIPTS . push ( element . outerHTML ) ;
40
+ scripts . push ( element . outerHTML ) ;
71
41
break ;
72
42
case 'STYLE' :
73
- STYLES . push ( element . outerHTML ) ;
43
+ styles . push ( element . outerHTML ) ;
74
44
break ;
75
45
case 'LINK' :
76
- LINKS . push ( element . outerHTML ) ;
46
+ links . push ( element . outerHTML ) ;
77
47
break ;
78
48
case 'META' :
79
- META . push ( element . outerHTML ) ;
49
+ meta . push ( element . outerHTML ) ;
80
50
break ;
81
51
default :
82
52
break ;
83
53
}
84
54
}
85
55
86
56
return {
87
- title : doc . title ,
88
57
// tslint:disable-next-line: no-non-null-assertion
89
- appNode : doc . querySelector ( appSelector ) ! . outerHTML ,
90
- scripts : SCRIPTS . join ( '\n' ) ,
91
- styles : STYLES . join ( '\n' ) ,
92
- meta : META . join ( '\n' ) ,
93
- links : LINKS . join ( '\n' )
58
+ html : doc . querySelector ( appSelector ) ! . outerHTML ,
59
+ globals : {
60
+ title : doc . title ,
61
+ scripts : scripts . join ( '\n' ) ,
62
+ styles : styles . join ( '\n' ) ,
63
+ meta : meta . join ( '\n' ) ,
64
+ links : links . join ( '\n' )
65
+ }
94
66
} ;
95
67
}
96
68
@@ -109,7 +81,7 @@ export async function ngAspnetCoreEngine(options: Readonly<IEngineOptions>)
109
81
const compiler : Compiler = compilerFactory . createCompiler ( [
110
82
{
111
83
providers : [
112
- { provide : ResourceLoader , useClass : FileLoader , deps : [ ] }
84
+ { provide : ResourceLoader , useClass : ɵFileLoader , deps : [ ] }
113
85
]
114
86
}
115
87
] ) ;
@@ -132,18 +104,10 @@ export async function ngAspnetCoreEngine(options: Readonly<IEngineOptions>)
132
104
} ) ;
133
105
134
106
const doc = result . moduleRef . injector . get ( DOCUMENT ) ;
135
- const universalData = _getUniversalData ( doc ) ;
136
107
137
108
return {
138
- html : universalData . appNode ,
139
109
moduleRef : result . moduleRef ,
140
- globals : {
141
- styles : universalData . styles ,
142
- title : universalData . title ,
143
- scripts : universalData . scripts ,
144
- meta : universalData . meta ,
145
- links : universalData . links
146
- }
110
+ ..._getUniversalData ( doc ) ,
147
111
} ;
148
112
}
149
113
0 commit comments