From 4c03e0e91c0820f256b3d9c70d9e8dea133e7630 Mon Sep 17 00:00:00 2001 From: icejix <150977660+icejix@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:00:06 -0400 Subject: [PATCH 1/2] Add typescript instructions to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 890405d..7128307 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ sudo apt-get install node npm npm install ``` +You'll also need to install and run the Typescript compiler inside the server folder: +```sh +sudo npm install -g typescript +tsc +``` + The most complex part is doing setup for HTTPS (optional): - You must have a certificate, you can get one for free from [Let's Encrypt](https://letsencrypt.org) - You will need to create a directory called `cert` that will contain: From 55e335ca52ffaa8d622c768dc41ec7c0afab4191 Mon Sep 17 00:00:00 2001 From: icejix <150977660+icejix@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:02:24 -0400 Subject: [PATCH 2/2] Make email upon server error not happen by default --- main.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/main.js b/main.js index 21588aa..8e697fa 100644 --- a/main.js +++ b/main.js @@ -7,25 +7,27 @@ import util from "util"; import nodemailer from "nodemailer"; import JSONTransport from "nodemailer/lib/json-transport/index.js"; -const smtpPassword = fs.readFileSync("conf/smtp_password.txt", { "encoding": "utf-8" }); -let transport = nodemailer.createTransport({ - host: "smtp.ionos.com", - port: 587, - //secure: true, - auth: { - user: "no-reply@blocksverse.com", - pass: smtpPassword, - } -}); - -// verify connection configuration -transport.verify(function (error) { - if (error) { - console.log(error); - } else { - console.log("SMTP backend is ready"); - } - }); +const smtpPassword = fs.existsSync("conf/smtp_password.txt") ? fs.readFileSync("conf/smtp_password.txt", { "encoding": "utf-8" }) : false; +if(smtpPassword) { + var transport = nodemailer.createTransport({ + host: "smtp.ionos.com", + port: 587, + //secure: true, + auth: { + user: "no-reply@blocksverse.com", + pass: smtpPassword, + } + }); + + // verify connection configuration + transport.verify(function (error) { + if (error) { + console.log(error); + } else { + console.log("SMTP backend is ready"); + } + }); +} // Init logging const logFilePath = "latest.log"; @@ -153,7 +155,7 @@ process.on('SIGTERM', () => { }); }); -if (process.env.NODE_ENV === "production" || true) { +if ((process.env.NODE_ENV === "production" || true) && smtpPassword) { process.on("uncaughtException", (err) => { if (err === "exiting") return; if (err.stack) console.error(err.stack); @@ -170,4 +172,4 @@ if (process.env.NODE_ENV === "production" || true) { } console.log("The server is ready!"); -console.log("Note: If you want the server to be publicly accessible (outside your house), be sure to port-forward port 8080 (there are many tutorials on internet)") \ No newline at end of file +console.log("Note: If you want the server to be publicly accessible (outside your house), be sure to port-forward port 8080 (there are many tutorials on internet)")