From 050e5c25bc84b70a35a6f59f588e02b6f486ec7a Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Thu, 19 Mar 2020 12:12:16 -0400 Subject: [PATCH] . --- src/index.tsx | 18 +++++++++--------- src/test.ts | 11 ++++++++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 38dcacb..b114c82 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,7 @@ import express from "express"; import http from "http"; import https from "https"; -import { SMTPServer } from "smtp-server"; +import { SMTPServer, SMTPServerOptions } from "smtp-server"; import mailparser from "mailparser"; import React from "react"; import ReactDOMServer from "react-dom/server"; @@ -33,7 +33,7 @@ const webApp = express() ); }); -const emailApp = new SMTPServer({ +const emailApp: SMTPServerOptions = { authOptional: true, async onData(stream, session, callback) { const paths = session.envelope.rcptTo.flatMap(({ address }) => { @@ -65,10 +65,10 @@ const emailApp = new SMTPServer({ } callback(); } -}); +}; -export const webServer = http.createServer(webApp); -export const emailServer = emailApp; +export const developmentWebServer = http.createServer(webApp); +export const developmentEmailServer = new SMTPServer(emailApp); if (process.env.NODE_ENV === "production") { const productionWebApp = express() @@ -95,11 +95,11 @@ if (process.env.NODE_ENV === "production") { ) }; http.createServer(productionWebApp).listen(80); - https.createServer(productionWebApp).listen(443); - emailServer.listen(25); + https.createServer(credentials, productionWebApp).listen(443); + new SMTPServer({ ...credentials, ...emailApp }).listen(25); } else { - webServer.listen(8000); - emailServer.listen(2525); + developmentWebServer.listen(8000); + developmentEmailServer.listen(2525); } type Inbox = { diff --git a/src/test.ts b/src/test.ts index 04cd386..7bb73b3 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,4 +1,9 @@ -import { webServer, emailServer, feedPath, feedEmail } from "."; +import { + developmentWebServer, + developmentEmailServer, + feedPath, + feedEmail +} from "."; import nodemailer from "nodemailer"; import fetch from "node-fetch"; import fs from "fs"; @@ -58,8 +63,8 @@ describe("receive email", () => { }); afterAll(() => { - webServer.close(); - emailServer.close(() => {}); + developmentWebServer.close(); + developmentEmailServer.close(() => {}); }); async function createFeed(): Promise {