-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
34 lines (26 loc) · 793 Bytes
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import express from 'express';
import React from 'react';
import ReactServerDOM from 'react-dom/server';
import { Provider } from 'react-redux';
import { renderPage } from './common';
import Main from './Components/Main';
import Users from './Components/Users';
import configureStore from './Store';
const router = express.Router();
router.get('/page', (req, res) => {
// Fetch data from database.
const initialState = {
users: ['John', 'Bob', 'Tony']
};
const store = configureStore(initialState);
const html = ReactServerDOM.renderToString(
<Provider store={store}>
<Main>
<Users />
</Main>
</Provider>
);
res.status(200);
res.send(renderPage(html));
});
module.exports = router;