From 50fb6a429bfb0a98af0ed6eebb627628fc1e968e Mon Sep 17 00:00:00 2001 From: lyc8503 Date: Sun, 19 May 2024 16:35:06 +0800 Subject: [PATCH] fix #28: ipv6 target parse fix --- worker/src/monitor.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/worker/src/monitor.ts b/worker/src/monitor.ts index 1dda46e..1e6f8d4 100644 --- a/worker/src/monitor.ts +++ b/worker/src/monitor.ts @@ -16,8 +16,9 @@ export async function getStatus( if (monitor.method === 'TCP_PING') { // TCP port endpoint monitor try { - const [hostname, port] = monitor.target.split(':') - const socket = connect({ hostname: hostname, port: Number(port) }) + // This is not a real https connection, but we need to add a dummy `https://` to parse the hostname & port + const parsed = new URL("https://" + monitor.target) + const socket = connect({ hostname: parsed.hostname, port: Number(parsed.port) }) // Now we have an `opened` promise! // @ts-ignore