From d4329ae706f0be7bd061465f478c65f739fcf98a Mon Sep 17 00:00:00 2001 From: nightness Date: Wed, 10 Nov 2021 18:25:28 -0600 Subject: [PATCH] work around if NGROK_SERVERHOST isn't in ../.env --- ngrok.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ngrok.js b/ngrok.js index a57d28c..bac8ee4 100644 --- a/ngrok.js +++ b/ngrok.js @@ -47,12 +47,21 @@ fs.readFile(dotenvFile, "utf8", (err, data) => { const url = await ngrok.connect({ authtoken, proto, addr }); // Rebuild lines with the new url + let found = false; lines = lines.map((element) => { const [name] = element.split("="); - if (name === "NGROK_SERVERHOST") return `${name}=${url}`; + if (name === "NGROK_SERVERHOST") { + found = true; + return `${name}=${url}`; + } return element; }); + // Is this variable already in the .env, if not add it. + if (!found) { + lines.unshift(`NGROK_SERVERHOST=${url}`) + } + // convert back to string format let writeData = ""; lines.forEach((element) => {