2020-03-18 04:07:48 +01:00
|
|
|
import express from "express";
|
|
|
|
import React from "react";
|
2020-03-18 18:38:09 +01:00
|
|
|
import {
|
|
|
|
Inbox,
|
|
|
|
Layout,
|
|
|
|
Form,
|
|
|
|
Created,
|
|
|
|
Feed,
|
|
|
|
newToken,
|
2020-03-18 20:21:44 +01:00
|
|
|
feedPath,
|
|
|
|
renderHtml,
|
|
|
|
renderXml
|
2020-03-18 18:38:09 +01:00
|
|
|
} from "./components";
|
2020-03-18 17:22:18 +01:00
|
|
|
import fs from "fs";
|
2020-03-18 04:07:48 +01:00
|
|
|
|
2020-03-18 20:21:44 +01:00
|
|
|
export const app = express();
|
2020-03-18 04:07:48 +01:00
|
|
|
|
|
|
|
app.use(express.static("static"));
|
2020-03-18 20:33:10 +01:00
|
|
|
app.use(express.urlencoded({ extended: true }));
|
2020-03-18 04:07:48 +01:00
|
|
|
|
|
|
|
app.get("/", (req, res) =>
|
2020-03-18 05:49:41 +01:00
|
|
|
res.send(
|
2020-03-18 20:21:44 +01:00
|
|
|
renderHtml(
|
2020-03-18 16:12:46 +01:00
|
|
|
<Layout>
|
|
|
|
<Form></Form>
|
|
|
|
</Layout>
|
|
|
|
)
|
2020-03-18 05:49:41 +01:00
|
|
|
)
|
2020-03-18 04:07:48 +01:00
|
|
|
);
|
|
|
|
|
2020-03-18 17:22:18 +01:00
|
|
|
app.post("/", (req, res) => {
|
2020-03-18 18:38:09 +01:00
|
|
|
const inbox: Inbox = { name: req.body.name, token: newToken() };
|
2020-03-18 20:21:44 +01:00
|
|
|
fs.writeFileSync(feedPath(inbox.token), renderXml(Feed(inbox)));
|
2020-03-18 17:22:18 +01:00
|
|
|
res.send(
|
2020-03-18 20:21:44 +01:00
|
|
|
renderHtml(
|
2020-03-18 17:22:18 +01:00
|
|
|
<Layout>
|
2020-03-18 18:38:09 +01:00
|
|
|
<Created inbox={inbox}></Created>
|
2020-03-18 17:22:18 +01:00
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-03-18 20:21:44 +01:00
|
|
|
if (require.main === module) app.listen(8000);
|