Extract ports

This commit is contained in:
Leandro Facchinetti 2020-04-06 09:34:44 -04:00
parent 32e7fa4fbd
commit 64db4b3a7b
3 changed files with 9 additions and 6 deletions

View File

@ -45,6 +45,7 @@
"script": "lib",
"env": {
"NODE_ENV": "production",
"WEB_PORT": "8000",
"EMAIL_PORT": "25"
}
},

View File

@ -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 (

View File

@ -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<string> {