@@ -12,12 +12,12 @@ const favicon = require('serve-favicon')
12
12
const serialize = require ( 'serialize-javascript' )
13
13
const createBundleRenderer = require ( 'vue-server-renderer' ) . createBundleRenderer
14
14
15
- var allowCrossDomain = function ( req , res , next ) {
16
- res . header ( 'Access-Control-Allow-Origin' , 'fullstackweekly-client.azureedge.net' ) ;
17
- res . header ( 'Access-Control-Allow-Methods' , 'GET,PUT,POST,DELETE' ) ;
18
- res . header ( 'Access-Control-Allow-Headers' , 'Content-Type' ) ;
15
+ var allowCrossDomain = function ( req , res , next ) {
16
+ res . header ( 'Access-Control-Allow-Origin' , 'fullstackweekly-client.azureedge.net' )
17
+ res . header ( 'Access-Control-Allow-Methods' , 'GET,PUT,POST,DELETE' )
18
+ res . header ( 'Access-Control-Allow-Headers' , 'Content-Type' )
19
19
20
- next ( ) ;
20
+ next ( )
21
21
}
22
22
23
23
function shouldCompress ( req , res ) {
@@ -28,16 +28,16 @@ function shouldCompress (req, res) {
28
28
return true
29
29
}
30
30
31
- var cacheControl = function ( req , res , next ) {
31
+ var cacheControl = function ( req , res , next ) {
32
32
if ( isProd ) {
33
33
res . header ( 'Cache-Control' , 'public, max-age=86400, no-cache' ) // one day
34
34
} else {
35
35
res . header ( 'Cache-Control' , 'no-cache, no-store, must-revalidate' ) // never
36
- }
36
+ }
37
37
next ( )
38
38
}
39
39
40
- var strictTransportSecurity = function ( req , res , next ) {
40
+ var strictTransportSecurity = function ( req , res , next ) {
41
41
res . header ( 'Strict-Transport-Security' , 'max-age=31536000; includeSubDomains; preload' )
42
42
next ( )
43
43
}
@@ -49,11 +49,11 @@ const indexHTML = (() => {
49
49
template = fs . readFileSync ( resolve ( './dist/index.html' ) , 'utf-8' )
50
50
template = template . replace ( / { { S C R I P T S } } / gmi, '' )
51
51
template = template . replace ( '{{ STYLES }}' , '' )
52
- template = template . replace ( '<link href="/assets/styles' , '<link href="{{ CDN }}/styles' )
52
+ template = template . replace ( '<link href="/assets/styles' , '<link rel="stylesheet" href="{{ CDN }}/styles media="all" ' )
53
53
template = template . replace ( / < s c r i p t t y p e = " t e x t \/ j a v a s c r i p t " s r c = " \/ a s s e t s / gmi, '<script type="text/javascript" src="{{ CDN }}/' )
54
54
} else {
55
55
template = fs . readFileSync ( resolve ( './index.html' ) , 'utf-8' )
56
- template = template . replace ( '{{ STYLES }}' , '<link rel="stylesheet" href="{{ CDN }}/styles.css">' )
56
+ template = template . replace ( '{{ STYLES }}' , '<link rel="stylesheet" href="{{ CDN }}/styles.css" media="all" >' )
57
57
template = template . replace ( / { { S C R I P T S } } / gmi, '<script defer src="{{ CDN }}/js/vendor.js"></script><script defer src="{{ CDN }}/js/app.js"></script>' )
58
58
}
59
59
template = template . replace ( / { { C D N } } / gmi, cdnClient )
@@ -75,7 +75,7 @@ if (isProd) {
75
75
app . use ( '/' , express . static ( resolve ( './dist' ) ) )
76
76
app . use ( favicon ( path . resolve ( __dirname , './dist/favicon.ico' ) ) )
77
77
} else {
78
- app . use ( '/dist' , express . static ( resolve ( './dist' ) ) )
78
+ app . use ( '/dist' , express . static ( resolve ( './dist' ) ) )
79
79
app . use ( favicon ( path . resolve ( __dirname , 'src/assets/favicon.ico' ) ) )
80
80
}
81
81
@@ -95,20 +95,19 @@ app.get('*', (req, res) => {
95
95
return res . end ( 'waiting for compilation... refresh in a moment.' )
96
96
}
97
97
98
- var s = Date . now ( )
99
98
const context = { url : req . url }
100
99
renderer . renderToString ( context , ( err , html ) => {
101
100
if ( err ) {
102
- console . log ( 'Error rendering to string: ' ) ;
103
- console . log ( err ) ;
104
- console . log ( err . message ) ;
105
- return res . status ( 200 ) . send ( 'Server Error' ) ;
101
+ console . log ( 'Error rendering to string: ' )
102
+ console . log ( err )
103
+ console . log ( err . message )
104
+ return res . status ( 200 ) . send ( 'Server Error' )
106
105
}
107
- html = indexHTML . replace ( '{{ APP }}' , html ) ;
108
- html = html . replace ( '{{ STATE }}' , `<script>window.__INITIAL_STATE__=${ serialize ( context . initialState , { isJSON : true } ) } </script>` ) ;
109
- res . setHeader ( 'Content-Length' , Buffer . byteLength ( html ) ) ;
110
- res . write ( html ) ;
111
- res . end ( ) ;
106
+ html = indexHTML . replace ( '{{ APP }}' , html )
107
+ html = html . replace ( '{{ STATE }}' , `<script>window.__INITIAL_STATE__=${ serialize ( context . initialState , { isJSON : true } ) } </script>` )
108
+ res . setHeader ( 'Content-Length' , Buffer . byteLength ( html ) )
109
+ res . write ( html )
110
+ res . end ( )
112
111
} )
113
112
} )
114
113
0 commit comments