Created
November 4, 2018 19:17
-
-
Save felippepuhle/245d9ae2f6fb0bcac814cb92af10a5f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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