Commit 1cefd6c8 authored by Rumkin's avatar Rumkin Committed by GitHub

Update server.js

Make header prepending more elegant and simple.
parent 90411aad
...@@ -59,10 +59,10 @@ app.get('*', (req, res) => { ...@@ -59,10 +59,10 @@ app.get('*', (req, res) => {
var s = Date.now() var s = Date.now()
const context = { url: req.url } const context = { url: req.url }
const renderStream = renderer.renderToStream(context) const renderStream = renderer.renderToStream(context)
let firstChunk = true
renderStream.on('data', chunk => {
if (firstChunk) { // Write head once
renderStream.once('data', () => {
res.write(html.head) res.write(html.head)
// embed initial store state // embed initial store state
if (context.initialState) { if (context.initialState) {
...@@ -72,8 +72,9 @@ app.get('*', (req, res) => { ...@@ -72,8 +72,9 @@ app.get('*', (req, res) => {
}</script>` }</script>`
) )
} }
firstChunk = false })
}
renderStream.on('data', chunk => {
res.write(chunk) res.write(chunk)
}) })
......
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