1+ const domino = require ( 'domino' ) ;
2+ const fs = require ( 'fs' ) ;
3+ const path = require ( 'path' ) ;
4+ const template = fs . readFileSync ( path . join ( __dirname , '.' , 'dist' , 'index.html' ) ) . toString ( ) ;
5+ const win = domino . createWindow ( template ) ;
6+ global [ 'window' ] = win ;
7+ global [ 'document' ] = win . document ;
8+ // global['XMLHttpRequest'] = require('xmlhttprequest').XMLHttpRequest;
9+ global [ 'Prism' ] = null ;
10+
111import { HttpClient } from '@angular/common/http' ;
212import 'reflect-metadata' ;
313import 'zone.js/dist/zone-node' ;
@@ -7,9 +17,6 @@ import * as compression from 'compression';
717import * as cookieparser from 'cookie-parser' ;
818const { provideModuleMap } = require ( '@nguniversal/module-map-ngfactory-loader' ) ;
919
10- const fs = require ( 'fs' ) ;
11- const path = require ( 'path' ) ;
12-
1320const files = fs . readdirSync ( `${ process . cwd ( ) } /dist-server` ) ;
1421const mainFiles = files . filter ( file => file . startsWith ( 'main' ) ) ;
1522const hash = mainFiles [ 0 ] . split ( '.' ) [ 1 ] ;
@@ -24,7 +31,6 @@ const app = express();
2431app . use ( compression ( ) ) ;
2532app . use ( cookieparser ( ) ) ;
2633
27- const template = fs . readFileSync ( path . join ( __dirname , '.' , 'dist' , 'index.html' ) ) . toString ( ) ;
2834
2935app . engine ( 'html' , ngExpressEngine ( {
3036 bootstrap : AppServerModuleNgFactory ,
@@ -39,12 +45,7 @@ app.set('views', 'src');
3945app . get ( '*.*' , express . static ( path . join ( __dirname , '.' , 'dist' ) ) ) ;
4046
4147app . get ( '*' , ( req , res ) => {
42- global [ 'window' ] = global ;
43- global [ 'document' ] = template ;
4448 global [ 'navigator' ] = req [ 'headers' ] [ 'user-agent' ] ;
45- global [ 'CSS' ] = null ;
46- // global['XMLHttpRequest'] = require('xmlhttprequest').XMLHttpRequest;
47- global [ 'Prism' ] = null ;
4849
4950 res . render ( '../dist/index' , {
5051 req : req ,
0 commit comments