Closed c21xdx closed 1 month ago
当初是电报群里发的,这段,想要反代到192.168.9.9:666 这样地址的没tls的htttp的ws节点,填了ip,协议,端口。 `import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
const targetWSHost = "192.168.9.9"; async function handler(req: Request): Promise { const url = new URL(req.url); const upgrade = req.headers.get("upgrade") || ""; if (upgrade.toLowerCase() != "websocket") { url.host = targetWSHost; return await fetch(url, req); }
const socketPromse = []; const { socket: downstream, response } = Deno.upgradeWebSocket(req); downstream.addEventListener("open", ()=>{ console.log('open----downstream-------'); }) url.host = targetWSHost url.protocol = 'http'; url.port = '666' const upstream = new WebSocket(url); socketPromse.push(new Promise((resolve) => upstream.addEventListener("open", resolve))); await Promise.all(socketPromse); console.log("Both WebSocket connections are open"); downstream.addEventListener("message", (message: any) => { upstream.send(message.data); }); downstream.addEventListener("error", (error: any) => { console.log("error", error); });
// Proxy messages from the upstream WebSocket connection to the downstream connection upstream.addEventListener("message", (message: any) => { downstream.send(message.data); }); upstream.addEventListener('error', (e: any) => { console.log("error", e); }); return response; }
serve(handler);` 但是没成功,日志提示 反代的是 https://192.168.9.9, 没有反代http://192.168.9.9:666。 这个要怎么设置啊?
当初是电报群里发的,这段,想要反代到192.168.9.9:666 这样地址的没tls的htttp的ws节点,填了ip,协议,端口。 `import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
const targetWSHost = "192.168.9.9"; async function handler(req: Request): Promise {
const url = new URL(req.url);
const upgrade = req.headers.get("upgrade") || "";
if (upgrade.toLowerCase() != "websocket") {
url.host = targetWSHost;
return await fetch(url, req);
}
const socketPromse = []; const { socket: downstream, response } = Deno.upgradeWebSocket(req); downstream.addEventListener("open", ()=>{ console.log('open----downstream-------'); }) url.host = targetWSHost url.protocol = 'http'; url.port = '666' const upstream = new WebSocket(url); socketPromse.push(new Promise((resolve) => upstream.addEventListener("open", resolve))); await Promise.all(socketPromse); console.log("Both WebSocket connections are open"); downstream.addEventListener("message", (message: any) => { upstream.send(message.data); }); downstream.addEventListener("error", (error: any) => { console.log("error", error); });
// Proxy messages from the upstream WebSocket connection to the downstream connection upstream.addEventListener("message", (message: any) => { downstream.send(message.data); }); upstream.addEventListener('error', (e: any) => { console.log("error", e); }); return response; }
serve(handler);` 但是没成功,日志提示 反代的是 https://192.168.9.9, 没有反代http://192.168.9.9:666。 这个要怎么设置啊?