refactoring
This commit is contained in:
parent
71b50b374b
commit
db3d2d8680
53
ngrok.js
53
ngrok.js
|
@ -43,32 +43,37 @@ fs.readFile(dotenvFile, "utf8", (err, data) => {
|
||||||
const addr = options?.addr ? options.addr : 3000;
|
const addr = options?.addr ? options.addr : 3000;
|
||||||
|
|
||||||
// Start ngrok
|
// Start ngrok
|
||||||
const url = await ngrok.connect({ authtoken, proto, addr });
|
try {
|
||||||
|
const url = await ngrok.connect({ authtoken, proto, addr });
|
||||||
|
|
||||||
// Rebuild lines with the new url
|
// Rebuild lines with the new url
|
||||||
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") return `${name}=${url}`;
|
||||||
return element;
|
return element;
|
||||||
});
|
});
|
||||||
|
|
||||||
// convert back to string format
|
// convert back to string format
|
||||||
let writeData = "";
|
let writeData = "";
|
||||||
lines.forEach((element) => {
|
lines.forEach((element) => {
|
||||||
writeData += element + "\n";
|
writeData += element + "\n";
|
||||||
});
|
});
|
||||||
writeData = writeData.slice(0, writeData.length - 1);
|
writeData = writeData.slice(0, writeData.length - 1);
|
||||||
|
|
||||||
// Write the new .env file
|
// Write the new .env file
|
||||||
fs.writeFile(dotenvFile, writeData, (err) => {
|
fs.writeFile(dotenvFile, writeData, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.clear();
|
console.clear();
|
||||||
console.log(`Started ngrok: protocol '${proto}', addr '${addr}'`)
|
console.log(`Started ngrok: protocol '${proto}', addr '${addr}'`);
|
||||||
console.log(`Your current ngrok url is ${url}.`);
|
console.log(`Your current ngrok url is ${url}.`);
|
||||||
console.log(`Your .env file has been updated.`);
|
console.log(`Your .env file has been updated.`);
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue