我有一台服务器通过我的机器上的Node运行。当我的pc在自定义子域下使用lt --subdomain mydomain --port 3000启动时,我注意到它在大约6小时后开始随机崩溃。我把这归因于节点服务器或本地隧道重新启动,或者是我的互联网质量很差。
当我重新运行上面的local隧道命令时,它说子域被接受了(给出了一个随机子域)。如何使本地隧道正确关闭隧道以允许重用我的子域?
发布于 2022-04-23 10:03:54
如果发生连接错误,我已经成功地创建了一个重新挖掘/重新启动隧道的类。这不是问题的解决办法,但它防止了问题的发生。我已经用了一年的时间来解决这个问题,没有一个问题,所以我希望它也适用于你。
easy-tunnel.js
const { exec } = require("child_process")
const colours = require("colors")
const base_host = 'http://localtunnel.me'
class EasyTunnel {
/**
*
* @param {number} port
* @param {string} subdomain
* @param {string} [host] defaults to 'http://localtunnel.me'
*/
constructor(port, subdomain, host) {
this.port = port
this.subdomain = subdomain
this.host = host ? host : base_host
}
/**
* Start the EasyTunnel
* @param {string} [status] used so redigging does not show initial dig message
*/
start(status) {
if (status != 'redig') console.log(`> Dug a tunnel for ${this.subdomain.yellow} on port ${this.port.toString().cyan} at ${this.host.green}`)
exec(`lt --subdomain ${this.subdomain} --port ${this.port} --host ${this.host}`, async (err, out) => {
if (err.toString().includes('connection refused')) {
this.start("redig")
console.log("> Redigging tunnel")
}
})
}
}
module.exports = EasyTunnelmain-app.js
var express = require("express")
var easyTunnel = require("./imports/easy-tunnel")
var port = 3000
var localtunnel = new easyTunnel(port, 'website-name')
var app = express();
app.get("/", (req, res) => {
res.send(":)")
}
app.listen(port, () => localtunnel.start());https://stackoverflow.com/questions/66296627
复制相似问题