Created
December 3, 2017 10:05
-
-
Save nukosuke/dc85b30c72f777376b3275bcd3d4f422 to your computer and use it in GitHub Desktop.
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 * as Koa from "koa"; | |
import * as React from "react"; | |
import * as ReactDOM from "react-dom/server"; | |
import { Helmet } from "react-helmet"; | |
import Application from "./components/Application"; | |
const app = new Koa(); | |
app.use(ctx => { | |
const markup = ReactDOM.renderToString(<Application/>); | |
const helmet = Helmet.renderStatic(); | |
ctx.body = ` | |
<!DOCTYPE html> | |
<html ${helmet.htmlAttributes.toString()}> | |
<head> | |
${helmet.title.toString()} | |
</head> | |
<body> | |
<div>${markup}</div> | |
</body> | |
</html> | |
`; | |
}); | |
app.listen(process.env.PORT || 3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment