This commit is contained in:
Leandro Facchinetti 2020-03-19 12:12:16 -04:00
parent bdffd62971
commit 050e5c25bc
2 changed files with 17 additions and 12 deletions

View File

@ -1,7 +1,7 @@
import express from "express"; import express from "express";
import http from "http"; import http from "http";
import https from "https"; import https from "https";
import { SMTPServer } from "smtp-server"; 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";
@ -33,7 +33,7 @@ const webApp = express()
); );
}); });
const emailApp = new SMTPServer({ const emailApp: SMTPServerOptions = {
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 }) => {
@ -65,10 +65,10 @@ const emailApp = new SMTPServer({
} }
callback(); callback();
} }
}); };
export const webServer = http.createServer(webApp); export const developmentWebServer = http.createServer(webApp);
export const emailServer = emailApp; export const developmentEmailServer = new SMTPServer(emailApp);
if (process.env.NODE_ENV === "production") { if (process.env.NODE_ENV === "production") {
const productionWebApp = express() const productionWebApp = express()
@ -95,11 +95,11 @@ if (process.env.NODE_ENV === "production") {
) )
}; };
http.createServer(productionWebApp).listen(80); http.createServer(productionWebApp).listen(80);
https.createServer(productionWebApp).listen(443); https.createServer(credentials, productionWebApp).listen(443);
emailServer.listen(25); new SMTPServer({ ...credentials, ...emailApp }).listen(25);
} else { } else {
webServer.listen(8000); developmentWebServer.listen(8000);
emailServer.listen(2525); developmentEmailServer.listen(2525);
} }
type Inbox = { type Inbox = {

View File

@ -1,4 +1,9 @@
import { webServer, emailServer, feedPath, feedEmail } from "."; import {
developmentWebServer,
developmentEmailServer,
feedPath,
feedEmail
} from ".";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import fetch from "node-fetch"; import fetch from "node-fetch";
import fs from "fs"; import fs from "fs";
@ -58,8 +63,8 @@ describe("receive email", () => {
}); });
afterAll(() => { afterAll(() => {
webServer.close(); developmentWebServer.close();
emailServer.close(() => {}); developmentEmailServer.close(() => {});
}); });
async function createFeed(): Promise<string> { async function createFeed(): Promise<string> {