This commit is contained in:
parent
accfadf188
commit
7298c7f63f
|
@ -6,9 +6,7 @@ module.exports = (require) => {
|
|||
console.log(`Web server started at ${webApplication.get("url")}`);
|
||||
});
|
||||
|
||||
emailApplication.listen(webApplication.get("email port"), () => {
|
||||
console.log(
|
||||
`Email server started on port ${webApplication.get("email port")}`
|
||||
);
|
||||
emailApplication.listen(new URL(webApplication.get("email")).port, () => {
|
||||
console.log(`Email server started at port ${webApplication.get("email")}`);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,8 +1,33 @@
|
|||
import { webServer, emailServer, BASE_URL, EMAIL_DOMAIN, EMAIL_PORT } from ".";
|
||||
import { beforeAll, afterAll, describe, test, expect } from "@jest/globals";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import http from "http";
|
||||
import net from "net";
|
||||
import fs from "fs";
|
||||
import * as got from "got";
|
||||
import nodemailer from "nodemailer";
|
||||
import axios from "axios";
|
||||
import qs from "qs";
|
||||
import { JSDOM } from "jsdom";
|
||||
import killTheNewsletter from ".";
|
||||
|
||||
let webServer: http.Server;
|
||||
let emailServer: net.Server;
|
||||
let webClient: got.Got;
|
||||
let emailClient: nodemailer.Transporter;
|
||||
beforeAll(() => {
|
||||
const rootDirectory = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), "kill-the-newsletter--test--")
|
||||
);
|
||||
const { webApplication, emailApplication } = killTheNewsletter(rootDirectory);
|
||||
webServer = webApplication.listen(new URL(webApplication.get("url")).port);
|
||||
emailServer = emailApplication.listen(
|
||||
new URL(webApplication.get("email")).port
|
||||
);
|
||||
webClient = got.default.extend({ prefixUrl: webApplication.get("url") });
|
||||
emailClient = nodemailer.createTransport(webApplication.get("email"));
|
||||
});
|
||||
afterAll(() => {
|
||||
webServer.close();
|
||||
emailServer.close();
|
||||
});
|
||||
|
||||
test("create feed", async () => {
|
||||
const identifier = await createFeed();
|
||||
|
@ -235,12 +260,6 @@ test("‘noindex’ header", async () => {
|
|||
);
|
||||
});
|
||||
|
||||
const webClient = axios.create({
|
||||
baseURL: BASE_URL,
|
||||
});
|
||||
const emailClient = nodemailer.createTransport(
|
||||
`smtp://${EMAIL_DOMAIN}:${EMAIL_PORT}`
|
||||
);
|
||||
afterAll(() => {
|
||||
webServer.close();
|
||||
emailServer.close();
|
||||
|
|
10
src/index.ts
10
src/index.ts
|
@ -20,8 +20,7 @@ export default function killTheNewsletter(
|
|||
const webApplication = express();
|
||||
|
||||
webApplication.set("url", "http://localhost:4000");
|
||||
webApplication.set("email port", 2525);
|
||||
webApplication.set("email host", "localhost");
|
||||
webApplication.set("email", "smtp://localhost:2525");
|
||||
webApplication.set("administrator", "mailto:kill-the-newsletter@leafac.com");
|
||||
|
||||
fs.ensureDirSync(rootDirectory);
|
||||
|
@ -287,7 +286,8 @@ export default function killTheNewsletter(
|
|||
<p>
|
||||
Sign up for the newsletter with<br />
|
||||
<code class="copyable"
|
||||
>${feedReference}@${webApplication.get("email host")}</code
|
||||
>${feedReference}@${new URL(webApplication.get("email"))
|
||||
.hostname}</code
|
||||
>
|
||||
</p>
|
||||
<p>
|
||||
|
@ -376,7 +376,7 @@ export default function killTheNewsletter(
|
|||
<title>${feed.title}</title>
|
||||
<subtitle
|
||||
>Kill the Newsletter! Inbox:
|
||||
${feedReference}@${webApplication.get("email host")} →
|
||||
${feedReference}@${new URL(webApplication.get("email")).hostname} →
|
||||
${webApplication.get("url")}/feeds/${feedReference}.xml</subtitle
|
||||
>
|
||||
<updated>${new Date(feed.updatedAt).toISOString()}</updated>
|
||||
|
@ -443,7 +443,7 @@ export default function killTheNewsletter(
|
|||
disabledCommands: ["AUTH", "STARTTLS"],
|
||||
async onData(stream, session, callback) {
|
||||
try {
|
||||
const atHost = "@" + webApplication.get("email host");
|
||||
const atHost = "@" + new URL(webApplication.get("email")).hostname;
|
||||
const email = await mailparser.simpleParser(stream);
|
||||
const from = email.from?.text ?? "";
|
||||
const subject = email.subject ?? "";
|
||||
|
|
Loading…
Reference in New Issue