diff --git a/package-lock.json b/package-lock.json index 1f712d1..152c41c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -911,6 +911,15 @@ "integrity": "sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==", "dev": true }, + "@types/xml2js": { + "version": "0.4.5", + "resolved": "https://registry.npmjs.org/@types/xml2js/-/xml2js-0.4.5.tgz", + "integrity": "sha512-yohU3zMn0fkhlape1nxXG2bLEGZRc1FeqF80RoHaYXJN7uibaauXfhzhOJr1Xh36sn+/tx21QAOf07b/xYVk1w==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/yargs": { "version": "15.0.4", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.4.tgz", @@ -1841,10 +1850,19 @@ } }, "crypto-random-string": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz", - "integrity": "sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=", - "dev": true + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-3.2.0.tgz", + "integrity": "sha512-8vPu5bsKaq2uKRy3OL7h1Oo7RayAWB8sYexLKAqvCXVib8SxgbmoF1IN4QMKjBv8uI8mp5gPPMbiRah25GMrVQ==", + "requires": { + "type-fest": "^0.8.1" + }, + "dependencies": { + "type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==" + } + } }, "cssom": { "version": "0.4.4", @@ -6621,6 +6639,14 @@ "dev": true, "requires": { "crypto-random-string": "^1.0.0" + }, + "dependencies": { + "crypto-random-string": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz", + "integrity": "sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=", + "dev": true + } } }, "unpipe": { diff --git a/package.json b/package.json index d1732e7..e4480e4 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "develop": "concurrently \"tsc --watch\" \"nodemon lib/server.js\"" }, "dependencies": { + "crypto-random-string": "^3.2.0", "express": "^4.17.1", "react": "^16.13.0", "react-dom": "^16.13.0", @@ -12,8 +13,10 @@ "devDependencies": { "@types/express": "^4.17.3", "@types/jest": "^25.1.4", + "@types/node": "^13.9.1", "@types/react": "^16.9.23", "@types/react-dom": "^16.9.5", + "@types/xml2js": "^0.4.5", "concurrently": "^5.1.0", "jest": "^25.1.0", "nodemon": "^2.0.2", diff --git a/src/components.tsx b/src/components.tsx index 57d8e02..8150a15 100644 --- a/src/components.tsx +++ b/src/components.tsx @@ -80,3 +80,38 @@ export class Form extends React.Component { ); } } + +export class Created extends React.Component<{ name: string; token: string }> { + render() { + return ( + <> +

“{this.props.name}” Inbox Created

+

+ Sign up for the newsletter with +
+ {this.props.token}@kill-the-newsletter.com +

+

+ Subscribe to the Atom feed at +
+ + https://www.kill-the-newsletter.com/feeds/{this.props.token}.xml + +

+

+ Don’t share these addresses. +
+ They contain a security token that other people could use +
+ to send you spam and to control your newsletter subscriptions. +

+

Enjoy your readings!

+

+ + Create Another Inbox + +

+ + ); + } +} diff --git a/src/server.tsx b/src/server.tsx index 47336cd..c2cd406 100644 --- a/src/server.tsx +++ b/src/server.tsx @@ -1,11 +1,14 @@ import express from "express"; import React from "react"; import ReactDOMServer from "react-dom/server"; -import { Layout, Form } from "./components"; +import { Layout, Form, Created } from "./components"; +import fs from "fs"; +import cryptoRandomString from "crypto-random-string"; const app = express(); app.use(express.static("static")); +app.use(express.urlencoded()); app.get("/", (req, res) => res.send( @@ -17,6 +20,22 @@ app.get("/", (req, res) => ) ); +app.post("/", (req, res) => { + res.send( + render( + + + + ) + ); +}); + app.listen(8000); function render(component: React.ReactElement): string {