Skip to content

Instantly share code, notes, and snippets.

@galenweber
Last active July 7, 2018 01:11
Show Gist options
  • Save galenweber/e48c5a292d2e858d895f667ab3a966c1 to your computer and use it in GitHub Desktop.
Save galenweber/e48c5a292d2e858d895f667ab3a966c1 to your computer and use it in GitHub Desktop.
Primary logic of express server for SSR React application
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