From 64db4b3a7b6232c1d164e0bda1110da7a63419db Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Mon, 6 Apr 2020 09:34:44 -0400 Subject: [PATCH] Extract ports --- package.json | 1 + src/index.tsx | 7 +++++-- src/test.ts | 7 +++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index f0b4181..7a2ee92 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "script": "lib", "env": { "NODE_ENV": "production", + "WEB_PORT": "8000", "EMAIL_PORT": "25" } }, diff --git a/src/index.tsx b/src/index.tsx index bdd4c40..df6e432 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -8,6 +8,9 @@ import { promises as fs } from "fs"; import writeFileAtomic from "write-file-atomic"; import cryptoRandomString from "crypto-random-string"; +export const WEB_PORT = process.env.WEB_PORT ?? 8000; +export const EMAIL_PORT = process.env.EMAIL_PORT ?? 2525; + export const webServer = express() .use(express.static("static")) .use(express.urlencoded({ extended: true })) @@ -71,7 +74,7 @@ export const webServer = express() ) ) ) - .listen(process.env.WEB_PORT ?? 8000); + .listen(WEB_PORT); export const emailServer = new SMTPServer({ disabledCommands: ["AUTH", "STARTTLS"], @@ -111,7 +114,7 @@ export const emailServer = new SMTPServer({ callback(new Error("Failed to receive message. Please try again.")); }); }, -}).listen(process.env.EMAIL_PORT ?? 2525); +}).listen(EMAIL_PORT); function Layout({ children }: { children: React.ReactNode }) { return ( diff --git a/src/test.ts b/src/test.ts index ca72d11..7d78f55 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,8 +1,7 @@ -import { webServer, emailServer } from "."; +import { webServer, emailServer, WEB_PORT, EMAIL_PORT } from "."; import nodemailer from "nodemailer"; import axios from "axios"; import qs from "qs"; -import { AddressInfo } from "net"; test("create feed", async () => { const identifier = await createFeed(); @@ -154,10 +153,10 @@ afterAll(() => { }); const webClient = axios.create({ - baseURL: `http://localhost:${(webServer.address() as AddressInfo).port}`, + baseURL: `http://localhost:${WEB_PORT}`, }); const emailClient = nodemailer.createTransport( - `smtp://localhost:${(emailServer.address() as AddressInfo).port}` + `smtp://localhost:${EMAIL_PORT}` ); async function createFeed(): Promise {