Skip to content

Commit e56060a

Browse files
committed
tweak server.js (put scripts after content)
1 parent c3a6de3 commit e56060a

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

server.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ app.get('*', (req, res) => {
5959
var s = Date.now()
6060
const context = { url: req.url }
6161
const renderStream = renderer.renderToStream(context)
62-
63-
64-
// Write head once
65-
renderStream.once('data', () => {
66-
res.write(html.head)
62+
63+
res.write(html.head)
64+
65+
renderStream.on('data', chunk => {
66+
res.write(chunk)
67+
})
68+
69+
renderStream.on('end', () => {
6770
// embed initial store state
6871
if (context.initialState) {
6972
res.write(
@@ -72,13 +75,6 @@ app.get('*', (req, res) => {
7275
}</script>`
7376
)
7477
}
75-
})
76-
77-
renderStream.on('data', chunk => {
78-
res.write(chunk)
79-
})
80-
81-
renderStream.on('end', () => {
8278
res.end(html.tail)
8379
console.log(`whole request: ${Date.now() - s}ms`)
8480
})

0 commit comments

Comments
 (0)