kill-the-newsletter/src/server.tsx

25 lines
486 B
TypeScript
Raw Normal View History

2020-03-18 04:07:48 +01:00
import express from "express";
import React from "react";
import ReactDOMServer from "react-dom/server";
2020-03-18 05:49:41 +01:00
import { Layout, Form } from "./components";
2020-03-18 04:07:48 +01:00
const app = express();
app.use(express.static("static"));
app.get("/", (req, res) =>
2020-03-18 05:49:41 +01:00
res.send(
2020-03-18 16:12:46 +01:00
render(
<Layout>
<Form></Form>
</Layout>
)
2020-03-18 05:49:41 +01:00
)
2020-03-18 04:07:48 +01:00
);
2020-03-18 16:12:46 +01:00
app.listen(8000);
function render(component: React.ReactElement): string {
return `<!DOCTYPE html>\n${ReactDOMServer.renderToStaticMarkup(component)}`;
}