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: 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)")