Skip to content

Instantly share code, notes, and snippets.

@felippepuhle
Created November 4, 2018 19:17
Show Gist options
  • Save felippepuhle/245d9ae2f6fb0bcac814cb92af10a5f1 to your computer and use it in GitHub Desktop.
Save felippepuhle/245d9ae2f6fb0bcac814cb92af10a5f1 to your computer and use it in GitHub Desktop.
import path from 'path';
import fs from 'fs';
import { ReleasyProvider, Config, Link, renderToStringWithData } from 'react-releasy';
// renderer middleware
const filePath = path.resolve(__dirname, '..', 'build', 'index.html');
fs.readFile(filePath, 'utf8', (htmlErr, htmlData) => {
if (htmlErr) {
return res.status(404).end()
}
const config = new Config({
link: new Link({
url: 'https://yourserveraddress.com/graphql',
}),
ssrMode: true,
});
renderToStringWithData(
<ReleasyProvider config={config}>
<App />
</ReleasyProvider>,
).then(({ html, scripts }) => {
return res.send(
htmlData
.replace('<div id="root"></div>', `<div id="root">${html}</div>${scripts}`)
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment