Last active
July 7, 2018 01:11
-
-
Save galenweber/e48c5a292d2e858d895f667ab3a966c1 to your computer and use it in GitHub Desktop.
Primary logic of express server for SSR React application
This file contains 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
server.get('/*', (req, res) => { | |
const component = router(req.url); | |
const element = React.createElement(component); | |
const page = renderToString(element); | |
// inject React page (as a string) into an HTML template | |
const html = template(page); | |
res.send(html); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment