Skip to content

Instantly share code, notes, and snippets.

@galenweber
Last active July 10, 2018 00:21
Show Gist options
  • Save galenweber/db778565b76dcf9b7f6ae562975e9ae6 to your computer and use it in GitHub Desktop.
Save galenweber/db778565b76dcf9b7f6ae562975e9ae6 to your computer and use it in GitHub Desktop.
Request handler that fetches content from prismic
server.get('/*', (req, res) => {
const component = router(req.url);
res.locals.ctx.api.getByUID('page', 'my-content')
.then((document) => {
const element = React.createElement(component, { document });
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