Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save galenweber/f3285f16572464ca3ad0941e5222ce9c to your computer and use it in GitHub Desktop.
Save galenweber/f3285f16572464ca3ad0941e5222ce9c to your computer and use it in GitHub Desktop.
server.get('/*', (req, res) => {
const component = router(req.url);
const prismicFetch = component.PRISMIC_FETCH_REQUEST
? component.PRISMIC_FETCH_REQUEST()
: (() => Promise.resolve());
prismicFetch(res.locals.ctx)
.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