This commit is contained in:
Leandro Facchinetti 2020-03-19 12:03:01 -04:00
parent f22e678b31
commit bdffd62971
1 changed files with 33 additions and 17 deletions

View File

@ -1,4 +1,6 @@
import express from "express"; import express from "express";
import http from "http";
import https from "https";
import { SMTPServer } from "smtp-server"; import { SMTPServer } from "smtp-server";
import mailparser from "mailparser"; import mailparser from "mailparser";
import React from "react"; import React from "react";
@ -65,11 +67,12 @@ const emailApp = new SMTPServer({
} }
}); });
export const webServer = webApp.listen( export const webServer = http.createServer(webApp);
process.env.NODE_ENV === "production" ? 80 : 8000 export const emailServer = emailApp;
);
if (process.env.NODE_ENV === "production") { if (process.env.NODE_ENV === "production") {
webApp.use((req, res, next) => { const productionWebApp = express()
.use((req, res, next) => {
if ( if (
req.protocol !== "https" || req.protocol !== "https" ||
req.hostname !== "www.kill-the-newsletter.com" req.hostname !== "www.kill-the-newsletter.com"
@ -79,12 +82,25 @@ if (process.env.NODE_ENV === "production") {
`https://www.kill-the-newsletter.com${req.originalUrl}` `https://www.kill-the-newsletter.com${req.originalUrl}`
); );
next(); next();
}); })
webApp.listen(443); .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/cert.pem",
"utf8"
)
};
http.createServer(productionWebApp).listen(80);
https.createServer(productionWebApp).listen(443);
emailServer.listen(25);
} else {
webServer.listen(8000);
emailServer.listen(2525);
} }
export const emailServer = emailApp.listen(
process.env.NODE_ENV === "production" ? 25 : 2525
);
type Inbox = { type Inbox = {
name: string; name: string;