This commit is contained in:
parent
c70ac68e91
commit
fd985e0b1d
|
@ -51,14 +51,14 @@
|
||||||
"ref": "origin/master",
|
"ref": "origin/master",
|
||||||
"repo": "git@github.com:leafac/www.kill-the-newsletter.com.git",
|
"repo": "git@github.com:leafac/www.kill-the-newsletter.com.git",
|
||||||
"path": "/root/www.kill-the-newsletter.com",
|
"path": "/root/www.kill-the-newsletter.com",
|
||||||
"pre-setup": "(ssh -o StrictHostKeyChecking=no git@github.com || true) && apt-get update && apt-get install -y build-essential software-properties-common && (curl -sL https://deb.nodesource.com/setup_13.x | bash -) && add-apt-repository universe && add-apt-repository ppa:certbot/certbot && apt-get install -y nodejs certbot && certbot certonly --standalone --non-interactive --agree-tos --email kill-the-newsletter@leafac.com --domain kill-the-newsletter.com --domain www.kill-the-newsletter.com",
|
"pre-setup": "(curl -sL https://deb.nodesource.com/setup_13.x | bash -) && sudo apt-get install -y nodejs build-essential && (curl https://getcaddy.com | bash -s personal) && (ssh -o StrictHostKeyChecking=no git@github.com || true)",
|
||||||
"ssh_options": [
|
"ssh_options": [
|
||||||
"ForwardAgent=yes",
|
"ForwardAgent=yes",
|
||||||
"StrictHostKeyChecking=no"
|
"StrictHostKeyChecking=no"
|
||||||
],
|
],
|
||||||
"TODO": [
|
"TODO": [
|
||||||
"https://certbot.eff.org/docs/using.html",
|
"Caddyfile",
|
||||||
"--pre-hook '/root/www.kill-the-newsletter.com/current/node_modules/.bin/pm2 stop all' --post-hook '/root/www.kill-the-newsletter.com/current/node_modules/.bin/pm2 start all'",
|
"/root/www.kill-the-newsletter.com/current/node_modules/.bin/pm2 startOrRestart all",
|
||||||
"env NODE_ENV=production npm ci",
|
"env NODE_ENV=production npm ci",
|
||||||
"rsync",
|
"rsync",
|
||||||
"pm2 startup OR pm2 save",
|
"pm2 startup OR pm2 save",
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import http from "http";
|
import { SMTPServer } from "smtp-server";
|
||||||
import https from "https";
|
|
||||||
import { SMTPServer, SMTPServerOptions } from "smtp-server";
|
|
||||||
import mailparser from "mailparser";
|
import mailparser from "mailparser";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOMServer from "react-dom/server";
|
import ReactDOMServer from "react-dom/server";
|
||||||
|
@ -9,7 +7,7 @@ import xml2js from "xml2js";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import cryptoRandomString from "crypto-random-string";
|
import cryptoRandomString from "crypto-random-string";
|
||||||
|
|
||||||
const webApp = express()
|
export const webServer = express()
|
||||||
.use(express.static("static"))
|
.use(express.static("static"))
|
||||||
.use(express.urlencoded({ extended: true }))
|
.use(express.urlencoded({ extended: true }))
|
||||||
.get("/", (req, res) =>
|
.get("/", (req, res) =>
|
||||||
|
@ -36,9 +34,10 @@ const webApp = express()
|
||||||
</Layout>
|
</Layout>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
})
|
||||||
|
.listen(8000, "localhost");
|
||||||
|
|
||||||
const emailApp: SMTPServerOptions = {
|
export const emailServer = new SMTPServer({
|
||||||
authOptional: true,
|
authOptional: true,
|
||||||
async onData(stream, session, callback) {
|
async onData(stream, session, callback) {
|
||||||
const paths = session.envelope.rcptTo.flatMap(({ address }) => {
|
const paths = session.envelope.rcptTo.flatMap(({ address }) => {
|
||||||
|
@ -69,27 +68,9 @@ const emailApp: SMTPServerOptions = {
|
||||||
fs.writeFileSync(path, renderXML(xml));
|
fs.writeFileSync(path, renderXML(xml));
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
}
|
},
|
||||||
};
|
...(process.env.NODE_ENV === "production"
|
||||||
|
? {
|
||||||
export const developmentWebServer = http.createServer(webApp);
|
|
||||||
export const developmentEmailServer = new SMTPServer(emailApp);
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === "production") {
|
|
||||||
const productionWebApp = express()
|
|
||||||
.use((req, res, next) => {
|
|
||||||
if (
|
|
||||||
req.protocol !== "https" ||
|
|
||||||
req.hostname !== "www.kill-the-newsletter.com"
|
|
||||||
)
|
|
||||||
return res.redirect(
|
|
||||||
301,
|
|
||||||
`https://www.kill-the-newsletter.com${req.originalUrl}`
|
|
||||||
);
|
|
||||||
next();
|
|
||||||
})
|
|
||||||
.use(webApp);
|
|
||||||
const credentials = {
|
|
||||||
key: fs.readFileSync(
|
key: fs.readFileSync(
|
||||||
"/etc/letsencrypt/live/kill-the-newsletter.com/privkey.pem",
|
"/etc/letsencrypt/live/kill-the-newsletter.com/privkey.pem",
|
||||||
"utf8"
|
"utf8"
|
||||||
|
@ -98,14 +79,9 @@ if (process.env.NODE_ENV === "production") {
|
||||||
"/etc/letsencrypt/live/kill-the-newsletter.com/fullchain.pem",
|
"/etc/letsencrypt/live/kill-the-newsletter.com/fullchain.pem",
|
||||||
"utf8"
|
"utf8"
|
||||||
)
|
)
|
||||||
};
|
}
|
||||||
http.createServer(productionWebApp).listen(80);
|
: {})
|
||||||
https.createServer(credentials, productionWebApp).listen(443);
|
}).listen(process.env.NODE_ENV === "production" ? 25 : 2525);
|
||||||
new SMTPServer({ ...credentials, ...emailApp }).listen(25);
|
|
||||||
} else {
|
|
||||||
developmentWebServer.listen(8000);
|
|
||||||
developmentEmailServer.listen(2525);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Layout({ children }: { children: React.ReactNode }) {
|
function Layout({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { developmentWebServer, developmentEmailServer, feedEmail } from ".";
|
import { webServer, emailServer, feedEmail } from ".";
|
||||||
import nodemailer from "nodemailer";
|
import nodemailer from "nodemailer";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
|
@ -58,9 +58,9 @@ describe("receive email", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
developmentWebServer.close();
|
webServer.close();
|
||||||
// FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43268
|
// FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43268
|
||||||
developmentEmailServer.close(() => {});
|
emailServer.close(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function createFeed(): Promise<string> {
|
async function createFeed(): Promise<string> {
|
||||||
|
|
Loading…
Reference in New Issue