diff --git a/public/index.html b/public/index.html index f7b8f2dc..e6fd9716 100644 --- a/public/index.html +++ b/public/index.html @@ -5,6 +5,7 @@ +
diff --git a/server/index.js b/server/index.js index 5b486f2a..b8e3aac8 100644 --- a/server/index.js +++ b/server/index.js @@ -21,12 +21,13 @@ const helmet = require('helmet'); const compression = require('compression'); const path = require('path'); const fs = require('fs'); -const auth = require('./auth'); +const qs = require('qs'); const _ = require('lodash'); const React = require('react'); const { createServerRenderContext } = require('react-router'); +const auth = require('./auth'); -// Construct the bundle path where the server side renering function +// Construct the bundle path where the server side rendering function // can be imported. const buildPath = path.resolve(__dirname, '..', 'build'); const manifestPath = path.join(buildPath, 'asset-manifest.json'); @@ -65,9 +66,17 @@ const template = _.template(indexHtml, { escape: reNoMatch, }); -function render(url, context) { - const { head, body } = renderApp(url, context); - return template({ title: head.title.toString(), body }); +function render(url, context, preloadedState) { + const { head, body } = renderApp(url, context, preloadedState); + + // Preloaded state needs to be passed for client side too. + const preloadedStateScript = ` + + `; + + return template({ title: head.title.toString(), preloadedStateScript, body }); } const env = process.env.NODE_ENV; @@ -91,7 +100,12 @@ app.use('/static', express.static(path.join(buildPath, 'static'))); app.get('*', (req, res) => { const context = createServerRenderContext(); - const html = render(req.url, context); + const filters = qs.parse(req.query); + + // TODO fetch this asynchronously + const preloadedState = { search: { filters } }; + + const html = render(req.url, context, preloadedState); const result = context.getResult(); if (result.redirect) { @@ -100,7 +114,7 @@ app.get('*', (req, res) => { // Do a second render pass with the context to clue