-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathserverEntry.js
More file actions
22 lines (19 loc) · 753 Bytes
/
serverEntry.js
File metadata and controls
22 lines (19 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import fs from 'fs';
import React from 'react';
import Transmit from 'react-transmit';
import Hello from './Hello.js';
function handleRender(req, res) {
Transmit.renderToString(Hello, {name: 'World'})
.then(({reactString, reactData}) => {
fs.readFile('./index.html', 'utf8', function (err, file) {
if (err) {
return console.log(err);
}
const document = file.replace(/<div id="app"><\/div>/, `<div id="app">${reactString}</div>`);
const output = Transmit.injectIntoMarkup(document, reactData, ['/built/client.js']);
res.send(output);
});
})
.catch(e => console.log(e));
}
export default handleRender;