Last active
July 10, 2018 00:21
-
-
Save galenweber/db778565b76dcf9b7f6ae562975e9ae6 to your computer and use it in GitHub Desktop.
Request handler that fetches content from prismic
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); | |
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