fix proxy

This commit is contained in:
JOLIMAITRE Matthieu 2023-12-10 23:24:28 +01:00
parent 33caad6317
commit 36891699c4

View file

@ -12,6 +12,11 @@ async function main() {
console.log("[proxy] listening on port", from_port, "redirecting to", to_ip, "port", to_port); console.log("[proxy] listening on port", from_port, "redirecting to", to_ip, "port", to_port);
for await (const connection of server) { for await (const connection of server) {
serve(to_ip, to_port, connection);
}
}
async function serve(to_ip: string, to_port: string, connection: Deno.Conn) {
try { try {
const client = await Deno.connect({ transport: "tcp", hostname: to_ip, port: parseInt(to_port) }); const client = await Deno.connect({ transport: "tcp", hostname: to_ip, port: parseInt(to_port) });
const promise_connection_done = connection.readable.pipeTo(client.writable); const promise_connection_done = connection.readable.pipeTo(client.writable);
@ -19,7 +24,6 @@ async function main() {
await Promise.all([promise_client_done, promise_connection_done]); await Promise.all([promise_client_done, promise_connection_done]);
} catch (_) { /* isok */ } } catch (_) { /* isok */ }
} }
}
export function proxy_command(from_port: number, to_ip: string, to_port: number) { export function proxy_command(from_port: number, to_ip: string, to_port: number) {
const path = new URL("", import.meta.url).pathname; const path = new URL("", import.meta.url).pathname;