Skip to content

Instantly share code, notes, and snippets.

@pahund
Last active February 16, 2017 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pahund/f07b12859d3dacf87af81a7bb07a341e to your computer and use it in GitHub Desktop.
Save pahund/f07b12859d3dacf87af81a7bb07a341e to your computer and use it in GitHub Desktop.
Code exerpts from universal-react-router4 – server/index.js
const routes = [
'/',
'/g/:gistId'
];
app.get('*', (req, res) => {
const match = routes.reduce((acc, route) => matchPath(req.url, route, { exact: true }) || acc, null);
if (!match) {
res.status(404).send(render(<NoMatch />));
return;
}
fetch('https://api.github.com/gists')
.then(r => r.json())
.then(gists =>
res.status(200).send(render(
(
<StaticRouter context={{}} location={req.url}>
<App gists={gists} />
</StaticRouter>
), gists
))
).catch(err => res.status(500).send(render(<Error />));
});
app.listen(3000, () => console.log('Demo app listening on port 3000'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment