-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.sample.js
More file actions
20 lines (19 loc) · 791 Bytes
/
Copy pathrenderer.sample.js
File metadata and controls
20 lines (19 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const zmq = require('zmq');
const renderToString = require('react-dom/server').renderToString;
const App = require('components/app').App; // replace this with your root component
const Helmet = require("react-helmet");
const channel = zmq.socket('rep');
const [doctype, constantHead, endOfBody] = require('index.html').split(/<html.+<head>|<!--REACT-->/);
channel.connect('ipc:///tmp/myapp');
channel.on('message', state => {
state = JSON.parse(state);
let content = renderToString(<App state={state}></App>);
let head = Helmet.rewind();
channel.send(`
${doctype}<html ${head.htmlAttributes.toString()}><head>
${head.title.toString()}
${head.meta.toString()}
${head.link.toString()}
${constantHead}${content}${endOfBody}
`);
});