work around if NGROK_SERVERHOST isn't in ../.env

This commit is contained in:
nightness 2021-11-10 18:25:28 -06:00
parent 9cdc73d5ba
commit d4329ae706
1 changed files with 10 additions and 1 deletions

View File

@ -47,12 +47,21 @@ fs.readFile(dotenvFile, "utf8", (err, data) => {
const url = await ngrok.connect({ authtoken, proto, addr }); const url = await ngrok.connect({ authtoken, proto, addr });
// Rebuild lines with the new url // Rebuild lines with the new url
let found = false;
lines = lines.map((element) => { lines = lines.map((element) => {
const [name] = element.split("="); const [name] = element.split("=");
if (name === "NGROK_SERVERHOST") return `${name}=${url}`; if (name === "NGROK_SERVERHOST") {
found = true;
return `${name}=${url}`;
}
return element; 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 // convert back to string format
let writeData = ""; let writeData = "";
lines.forEach((element) => { lines.forEach((element) => {