Better treatment of ports

This commit is contained in:
Leandro Facchinetti 2020-03-24 11:13:07 -04:00
parent 0b58dbfe11
commit d1a30baa52
3 changed files with 11 additions and 5 deletions

View File

@ -43,7 +43,8 @@
"name": "kill-the-newsletter", "name": "kill-the-newsletter",
"script": "lib", "script": "lib",
"env": { "env": {
"NODE_ENV": "production" "NODE_ENV": "production",
"EMAIL_PORT": "25"
} }
}, },
{ {

View File

@ -62,7 +62,7 @@ export const webServer = express()
) )
) )
) )
.listen(8000); .listen(process.env.WEB_PORT ?? 8000);
export const emailServer = new SMTPServer({ export const emailServer = new SMTPServer({
disabledCommands: ["AUTH", "STARTTLS"], disabledCommands: ["AUTH", "STARTTLS"],
@ -97,7 +97,7 @@ export const emailServer = new SMTPServer({
callback(error); callback(error);
}); });
} }
}).listen(process.env.NODE_ENV === "production" ? 25 : 2525); }).listen(process.env.EMAIL_PORT ?? 2525);
function Layout({ children }: { children: React.ReactNode }) { function Layout({ children }: { children: React.ReactNode }) {
return ( return (

View File

@ -2,6 +2,7 @@ import { webServer, emailServer } from ".";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import axios from "axios"; import axios from "axios";
import qs from "qs"; import qs from "qs";
import { AddressInfo } from "net";
test("create feed", async () => { test("create feed", async () => {
const identifier = await createFeed(); const identifier = await createFeed();
@ -112,8 +113,12 @@ afterAll(() => {
emailServer.close(() => {}); emailServer.close(() => {});
}); });
const webClient = axios.create({ baseURL: "http://localhost:8000" }); const webClient = axios.create({
const emailClient = nodemailer.createTransport("smtp://localhost:2525"); baseURL: `http://localhost:${(webServer.address() as AddressInfo).port}`
});
const emailClient = nodemailer.createTransport(
`smtp://localhost:${(emailServer.address() as AddressInfo).port}`
);
async function createFeed(): Promise<string> { async function createFeed(): Promise<string> {
return ( return (