(req, res)
| 25 | app.use(webpackHotMiddleware(compiler)) |
| 26 | |
| 27 | const handleRender = (req, res) => { |
| 28 | // Query our mock API asynchronously |
| 29 | fetchCounter(apiResult => { |
| 30 | // Read the counter from the request, if provided |
| 31 | const params = qs.parse(req.query) |
| 32 | const counter = parseInt(params.counter, 10) || apiResult || 0 |
| 33 | |
| 34 | // Compile an initial state |
| 35 | const preloadedState = { counter } |
| 36 | |
| 37 | // Create a new Redux store instance |
| 38 | const store = configureStore(preloadedState) |
| 39 | |
| 40 | // Render the component to a string |
| 41 | const html = renderToString( |
| 42 | <Provider store={store}> |
| 43 | <App /> |
| 44 | </Provider> |
| 45 | ) |
| 46 | |
| 47 | // Grab the initial state from our Redux store |
| 48 | const finalState = store.getState() |
| 49 | |
| 50 | // Send the rendered page back to the client |
| 51 | res.send(renderFullPage(html, finalState)) |
| 52 | }) |
| 53 | } |
| 54 | |
| 55 | // This is fired every time the server side receives a request |
| 56 | app.use(handleRender) |
nothing calls this directly
no test coverage detected