panrouter 6.3.5 → 6.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/pool-worker.mjs +27 -0
package/package.json
CHANGED
package/pool-worker.mjs
CHANGED
|
@@ -145,6 +145,10 @@ function connectToHub() {
|
|
|
145
145
|
ws.send(JSON.stringify({ type: "pong" }));
|
|
146
146
|
break;
|
|
147
147
|
|
|
148
|
+
case "test":
|
|
149
|
+
handleTestRequest(msg);
|
|
150
|
+
break;
|
|
151
|
+
|
|
148
152
|
case "upgrade":
|
|
149
153
|
handleUpgrade();
|
|
150
154
|
break;
|
|
@@ -348,6 +352,29 @@ function safeSend(data) {
|
|
|
348
352
|
}
|
|
349
353
|
}
|
|
350
354
|
|
|
355
|
+
// ─── 节点连通性测试 ─────────────────────────────────────────────────────────
|
|
356
|
+
|
|
357
|
+
function handleTestRequest(msg) {
|
|
358
|
+
const testReq = http.request({
|
|
359
|
+
hostname: "127.0.0.1",
|
|
360
|
+
port: SERVER_PORT,
|
|
361
|
+
path: "/dashboard",
|
|
362
|
+
method: "GET",
|
|
363
|
+
timeout: 8000,
|
|
364
|
+
}, (res) => {
|
|
365
|
+
// 只要收到响应就算通
|
|
366
|
+
let body = "";
|
|
367
|
+
res.on("data", (c) => body += c);
|
|
368
|
+
res.on("end", () => {
|
|
369
|
+
safeSend({ type: "test_result", reqId: msg.reqId, ok: true, status: res.statusCode, detail: body.slice(0, 200) });
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
testReq.on("error", (err) => {
|
|
373
|
+
safeSend({ type: "test_result", reqId: msg.reqId, ok: false, error: err.message });
|
|
374
|
+
});
|
|
375
|
+
testReq.end();
|
|
376
|
+
}
|
|
377
|
+
|
|
351
378
|
// ─── 心跳保活(每 25 秒发送 ping,避免 Cloudflare 闲置超时) ─────────────────
|
|
352
379
|
|
|
353
380
|
function startHeartbeat() {
|