Make ts-node a production dependency and use environment variables for configuration

This commit is contained in:
Nehal Patel 2021-10-05 23:54:28 -05:00
parent c7f520c9b7
commit 33de8f9be6
3 changed files with 22 additions and 12 deletions

View File

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

View File

@ -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": {

View File

@ -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]);