Created
February 18, 2018 19:00
-
-
Save galenweber/e1820f5415ed9a9db9bace2a92e97a5e to your computer and use it in GitHub Desktop.
Express server rendering React for React TypeScript SSR
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
import React from 'react'; | |
import express from 'express'; | |
import { renderToString } from 'react-dom/server'; | |
import Counter from '../containers/Counter'; | |
import html from '../html'; | |
const port = 3000; | |
const server = express(); | |
server.use(express.static('dist')); | |
server.get('/', (req, res) => { | |
const body = renderToString(React.createElement(Counter)); | |
res.send( | |
html({ | |
body | |
}) | |
); | |
}) | |
server.listen(3000, () => console.log('Example app listening on port 3000!')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment