Commit e56060a6 authored by Evan You's avatar Evan You

tweak server.js (put scripts after content)

parent c3a6de35
...@@ -60,10 +60,13 @@ app.get('*', (req, res) => { ...@@ -60,10 +60,13 @@ app.get('*', (req, res) => {
const context = { url: req.url } const context = { url: req.url }
const renderStream = renderer.renderToStream(context) const renderStream = renderer.renderToStream(context)
// Write head once
renderStream.once('data', () => {
res.write(html.head) res.write(html.head)
renderStream.on('data', chunk => {
res.write(chunk)
})
renderStream.on('end', () => {
// embed initial store state // embed initial store state
if (context.initialState) { if (context.initialState) {
res.write( res.write(
...@@ -72,13 +75,6 @@ app.get('*', (req, res) => { ...@@ -72,13 +75,6 @@ app.get('*', (req, res) => {
}</script>` }</script>`
) )
} }
})
renderStream.on('data', chunk => {
res.write(chunk)
})
renderStream.on('end', () => {
res.end(html.tail) res.end(html.tail)
console.log(`whole request: ${Date.now() - s}ms`) console.log(`whole request: ${Date.now() - s}ms`)
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment