This commit is contained in:
parent
c70ac68e91
commit
fd985e0b1d
|
@ -51,14 +51,14 @@
|
|||
"ref": "origin/master",
|
||||
"repo": "git@github.com:leafac/www.kill-the-newsletter.com.git",
|
||||
"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": [
|
||||
"ForwardAgent=yes",
|
||||
"StrictHostKeyChecking=no"
|
||||
],
|
||||
"TODO": [
|
||||
"https://certbot.eff.org/docs/using.html",
|
||||
"--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'",
|
||||
"Caddyfile",
|
||||
"/root/www.kill-the-newsletter.com/current/node_modules/.bin/pm2 startOrRestart all",
|
||||
"env NODE_ENV=production npm ci",
|
||||
"rsync",
|
||||
"pm2 startup OR pm2 save",
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import express from "express";
|
||||
import http from "http";
|
||||
import https from "https";
|
||||
import { SMTPServer, SMTPServerOptions } from "smtp-server";
|
||||
import { SMTPServer } from "smtp-server";
|
||||
import mailparser from "mailparser";
|
||||
import React from "react";
|
||||
import ReactDOMServer from "react-dom/server";
|
||||
|
@ -9,7 +7,7 @@ import xml2js from "xml2js";
|
|||
import fs from "fs";
|
||||
import cryptoRandomString from "crypto-random-string";
|
||||
|
||||
const webApp = express()
|
||||
export const webServer = express()
|
||||
.use(express.static("static"))
|
||||
.use(express.urlencoded({ extended: true }))
|
||||
.get("/", (req, res) =>
|
||||
|
@ -36,9 +34,10 @@ const webApp = express()
|
|||
</Layout>
|
||||
)
|
||||
);
|
||||
});
|
||||
})
|
||||
.listen(8000, "localhost");
|
||||
|
||||
const emailApp: SMTPServerOptions = {
|
||||
export const emailServer = new SMTPServer({
|
||||
authOptional: true,
|
||||
async onData(stream, session, callback) {
|
||||
const paths = session.envelope.rcptTo.flatMap(({ address }) => {
|
||||
|
@ -69,43 +68,20 @@ const emailApp: SMTPServerOptions = {
|
|||
fs.writeFileSync(path, renderXML(xml));
|
||||
}
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
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(
|
||||
"/etc/letsencrypt/live/kill-the-newsletter.com/privkey.pem",
|
||||
"utf8"
|
||||
),
|
||||
cert: fs.readFileSync(
|
||||
"/etc/letsencrypt/live/kill-the-newsletter.com/fullchain.pem",
|
||||
"utf8"
|
||||
)
|
||||
};
|
||||
http.createServer(productionWebApp).listen(80);
|
||||
https.createServer(credentials, productionWebApp).listen(443);
|
||||
new SMTPServer({ ...credentials, ...emailApp }).listen(25);
|
||||
} else {
|
||||
developmentWebServer.listen(8000);
|
||||
developmentEmailServer.listen(2525);
|
||||
}
|
||||
},
|
||||
...(process.env.NODE_ENV === "production"
|
||||
? {
|
||||
key: fs.readFileSync(
|
||||
"/etc/letsencrypt/live/kill-the-newsletter.com/privkey.pem",
|
||||
"utf8"
|
||||
),
|
||||
cert: fs.readFileSync(
|
||||
"/etc/letsencrypt/live/kill-the-newsletter.com/fullchain.pem",
|
||||
"utf8"
|
||||
)
|
||||
}
|
||||
: {})
|
||||
}).listen(process.env.NODE_ENV === "production" ? 25 : 2525);
|
||||
|
||||
function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { developmentWebServer, developmentEmailServer, feedEmail } from ".";
|
||||
import { webServer, emailServer, feedEmail } from ".";
|
||||
import nodemailer from "nodemailer";
|
||||
import axios from "axios";
|
||||
import qs from "qs";
|
||||
|
@ -58,9 +58,9 @@ describe("receive email", () => {
|
|||
});
|
||||
|
||||
afterAll(() => {
|
||||
developmentWebServer.close();
|
||||
webServer.close();
|
||||
// FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43268
|
||||
developmentEmailServer.close(() => {});
|
||||
emailServer.close(() => {});
|
||||
});
|
||||
|
||||
async function createFeed(): Promise<string> {
|
||||
|
|
Loading…
Reference in New Issue