MCPcopy Create free account
hub / github.com/denodrivers/postgres / createProxy

Function createProxy

tests/connection_test.ts:16–42  ·  view source on GitHub ↗
(
  target: Deno.Listener,
  source: { hostname: string; port: number },
)

Source from the content-addressed store, hash-verified

14import { getSocketName } from "../utils/utils.ts";
15
16function createProxy(
17 target: Deno.Listener,
18 source: { hostname: string; port: number },
19): { aborter: AbortController; proxy: Promise<void> } {
20 const aborter = new AbortController();
21
22 const proxy = (async () => {
23 for await (const conn of target) {
24 const outbound = await Deno.connect({
25 hostname: source.hostname,
26 port: source.port,
27 });
28
29 aborter.signal.addEventListener("abort", () => {
30 conn.close();
31 outbound.close();
32 });
33
34 await Promise.all([
35 conn.readable.pipeTo(outbound.writable),
36 outbound.readable.pipeTo(conn.writable),
37 ]).catch(() => {});
38 }
39 })();
40
41 return { aborter, proxy };
42}
43
44function getRandomString() {
45 return Math.random().toString(36).substring(7);

Callers 1

connection_test.tsFile · 0.85

Calls 1

connectMethod · 0.80

Tested by

no test coverage detected