Skip to content

Instantly share code, notes, and snippets.

@keithnorm
Created September 7, 2017 00:11
Show Gist options
  • Save keithnorm/1d4bec394bbacc7ef1300baa18877bfa to your computer and use it in GitHub Desktop.
Save keithnorm/1d4bec394bbacc7ef1300baa18877bfa to your computer and use it in GitHub Desktop.
// on the server
import { renderToStaticMarkup } from 'react-dom/server';
import MongoClient from 'mongodb';
app.get('*', (req, res) => {
var url = 'mongodb://localhost:27017/todo-app';
MongoClient.connect(url, function(err, db) {
res.status(200).render('layout', {
locals: {
body: renderToStaticMarkup(<TodoApp db={db}/>),
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment