首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LocalTunnel随机崩溃,子域不再工作

LocalTunnel随机崩溃,子域不再工作
EN

Stack Overflow用户
提问于 2021-02-20 21:14:18
回答 1查看 620关注 0票数 1

我有一台服务器通过我的机器上的Node运行。当我的pc在自定义子域下使用lt --subdomain mydomain --port 3000启动时,我注意到它在大约6小时后开始随机崩溃。我把这归因于节点服务器或本地隧道重新启动,或者是我的互联网质量很差。

当我重新运行上面的local隧道命令时,它说子域被接受了(给出了一个随机子域)。如何使本地隧道正确关闭隧道以允许重用我的子域?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-23 10:03:54

如果发生连接错误,我已经成功地创建了一个重新挖掘/重新启动隧道的类。这不是问题的解决办法,但它防止了问题的发生。我已经用了一年的时间来解决这个问题,没有一个问题,所以我希望它也适用于你。

easy-tunnel.js

代码语言:javascript
复制
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 = EasyTunnel

main-app.js

代码语言:javascript
复制
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());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66296627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档