Skip to content

Instantly share code, notes, and snippets.

@nukosuke
Created December 3, 2017 10:05
Show Gist options
  • Save nukosuke/dc85b30c72f777376b3275bcd3d4f422 to your computer and use it in GitHub Desktop.
Save nukosuke/dc85b30c72f777376b3275bcd3d4f422 to your computer and use it in GitHub Desktop.
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