@@ -4,10 +4,12 @@ const path = require('path');
44const template = fs . readFileSync ( path . join ( __dirname , '.' , 'dist' , 'index.html' ) ) . toString ( ) ;
55const win = domino . createWindow ( template ) ;
66const files = fs . readdirSync ( `${ process . cwd ( ) } /dist-server` ) ;
7+ import fetch from 'node-fetch' ;
78// const styleFiles = files.filter(file => file.startsWith('styles'));
89// const hashStyle = styleFiles[0].split('.')[1];
910// const style = fs.readFileSync(path.join(__dirname, '.', 'dist-server', `styles.${hashStyle}.bundle.css`)).toString();
1011
12+ win . fetch = fetch ;
1113global [ 'window' ] = win ;
1214Object . defineProperty ( win . document . body . style , 'transform' , {
1315 value : ( ) => {
@@ -97,24 +99,31 @@ app.get('*', (req, res) => {
9799
98100 // tslint:disable-next-line:no-console
99101 console . time ( `GET: ${ req . originalUrl } ` ) ;
100- res . render ( '../dist/index' , {
101- req : req ,
102- res : res ,
103- providers : [
104- {
105- provide : REQUEST , useValue : ( req )
106- } ,
107- {
108- provide : RESPONSE , useValue : ( res )
109- } ,
110- {
111- provide : 'ORIGIN_URL' ,
112- useValue : ( `${ http } ://${ req . headers . host } ` )
113- }
114- ]
115- } ) ;
116- // tslint:disable-next-line:no-console
117- console . timeEnd ( `GET: ${ req . originalUrl } ` ) ;
102+ res . render (
103+ '../dist/index' ,
104+ {
105+ req : req ,
106+ res : res ,
107+ providers : [
108+ {
109+ provide : REQUEST , useValue : ( req )
110+ } ,
111+ {
112+ provide : RESPONSE , useValue : ( res )
113+ } ,
114+ {
115+ provide : 'ORIGIN_URL' ,
116+ useValue : ( `${ http } ://${ req . headers . host } ` )
117+ }
118+ ]
119+ } ,
120+ ( err , html ) => {
121+ if ( ! ! err ) throw err ;
122+
123+ // tslint:disable-next-line:no-console
124+ console . timeEnd ( `GET: ${ req . originalUrl } ` ) ;
125+ res . send ( html ) ;
126+ } ) ;
118127} ) ;
119128
120129app . listen ( PORT , ( ) => {
0 commit comments