Skip to content

Instantly share code, notes, and snippets.

@koba04
Created October 1, 2017 14:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koba04/f6e90c2fb946f5df5faab83f9e8b8b93 to your computer and use it in GitHub Desktop.
Save koba04/f6e90c2fb946f5df5faab83f9e8b8b93 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import express from 'express';
import Html from './Html';
import App from './App';
const app = express();
app.use('/static', express.static('public'));
const initialData = {
name: 'World'
};
app.get('/', (req, res) => {
ReactDOMServer.renderToNodeStream(
<Html initialData={JSON.stringify(initialData)}>
<App {...initialData} name="World" />
</Html>
).pipe(res);
});
app.listen(3000, () => {
console.log('listening on port 3000...');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment