"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const localtunnel_1 = __importDefault(require("../localtunnel")); const debug_1 = __importDefault(require("debug")); const debugLog = (0, debug_1.default)('tunnel:client'); const port = process.env.PORT ? parseInt(process.env.PORT) : 23917; async function createTunnel() { debugLog('开始创建隧道, 端口: %d', port); try { debugLog('连接隧道服务器: %s', "https://23908.dev.d8dcloud.com"); const tunnel = await (0, localtunnel_1.default)({ port: port, host: "https://23908.dev.d8dcloud.com", }); console.log(`隧道已创建: ${tunnel.url}`); debugLog('隧道创建成功, URL: %s', tunnel.url); // 添加事件监听 tunnel.on("request", (info) => { console.log("隧道收到请求:", info); debugLog('处理请求: %o', info); }); tunnel.on("error", (err) => { console.error("隧道错误:", err); debugLog('发生错误: %o', err); // 尝试重新连接 debugLog('1秒后尝试重新连接...'); setTimeout(createTunnel, 1000); }); tunnel.on("close", () => { console.log("隧道关闭 - 尝试重新连接"); debugLog('隧道关闭,1秒后尝试重新连接...'); setTimeout(createTunnel, 1000); }); // 添加进程退出处理 process.on('SIGINT', () => { debugLog('收到退出信号,正在关闭隧道...'); tunnel.close(); process.exit(0); }); return tunnel; } catch (err) { console.error("创建隧道失败:", err); debugLog('创建隧道失败: %o', err); debugLog('1秒后重试...'); setTimeout(createTunnel, 1000); return null; } } // 启动隧道 createTunnel().catch((err) => { console.error("启动失败:", err); debugLog('启动失败: %o', err); }); // 添加未捕获异常处理 process.on('uncaughtException', (err) => { console.error('未捕获的异常:', err); debugLog('未捕获的异常: %o', err); }); process.on('unhandledRejection', (err) => { console.error('未处理的 Promise 拒绝:', err); debugLog('未处理的 Promise 拒绝: %o', err); });