From 33de8f9be6a88e3e7c508d66edf2ce7ef5ba4695 Mon Sep 17 00:00:00 2001 From: Nehal Patel Date: Tue, 5 Oct 2021 23:54:28 -0500 Subject: [PATCH] Make ts-node a production dependency and use environment variables for configuration --- Dockerfile | 6 +++--- package.json | 4 ++-- source/index.ts | 24 +++++++++++++++++------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index e85eed0..767b061 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,13 +12,13 @@ COPY . . VOLUME /kill-the-newsletter/static/feeds/ VOLUME /kill-the-newsletter/static/alternate/ -ENV WEB_PORT=8000 +ENV WEB_PORT=4000 ENV EMAIL_PORT=2525 -ENV BASE_URL=http://localhost:8000 +ENV BASE_URL=http://localhost:4000 ENV EMAIL_DOMAIN=localhost ENV ISSUE_REPORT=mailto:kill-the-newsletter@leafac.com -EXPOSE 8000 +EXPOSE 4000 EXPOSE 2525 CMD npx ts-node . \ No newline at end of file diff --git a/package.json b/package.json index 6c71a1f..2bdc0ea 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "fs-extra": "^9.1.0", "mailparser": "^3.1.0", "smtp-server": "^3.8.0", - "tagged-template-noop": "^2.1.1" + "tagged-template-noop": "^2.1.1", + "ts-node": "^9.1.1" }, "devDependencies": { "@types/express": "^4.17.11", @@ -52,7 +53,6 @@ "nodemailer": "^6.4.18", "prettier": "^2.2.1", "ts-jest": "^27.0.5", - "ts-node": "^9.1.1", "typescript": "^4.2.3" }, "jest": { diff --git a/source/index.ts b/source/index.ts index cfc3ca9..634597a 100644 --- a/source/index.ts +++ b/source/index.ts @@ -19,9 +19,15 @@ export default function killTheNewsletter( ): { webApplication: express.Express; emailApplication: SMTPServer } { const webApplication = express(); - webApplication.set("url", "http://localhost:4000"); - webApplication.set("email", "smtp://localhost:2525"); - webApplication.set("administrator", "mailto:kill-the-newsletter@leafac.com"); + const baseUrl = process.env.BASE_URL ?? "http://localhost:4000"; + webApplication.set("url", baseUrl); + + const smtpUrl = process.env.SMTP_URL ?? "smtp://localhost:2525"; + webApplication.set("email", smtpUrl); + + const issueReportEmail = + process.env.ISSUE_REPORT_EMAIL ?? "kill-the-newsletter@leafac.com"; + webApplication.set("administrator", `mailto:${issueReportEmail}`); fs.ensureDirSync(rootDirectory); const database = new Database( @@ -503,11 +509,15 @@ if (require.main === module) { const { webApplication, emailApplication } = killTheNewsletter( path.join(process.cwd(), "data") ); - webApplication.listen(new URL(webApplication.get("url")).port, () => { - console.log(`Web server started at ${webApplication.get("url")}`); + const webPort = + process.env.WEB_PORT ?? new URL(webApplication.get("url")).port; + webApplication.listen(webPort, () => { + console.log(`Web server started at port ${webPort}}`); }); - emailApplication.listen(new URL(webApplication.get("email")).port, () => { - console.log(`Email server started at ${webApplication.get("email")}`); + const emailPort = + process.env.EMAIL_PORT ?? new URL(webApplication.get("email")).port; + emailApplication.listen(emailPort, () => { + console.log(`Email server started at port ${emailPort}`); }); } else { const configurationFile = path.resolve(process.argv[2]);