MCPcopy Create free account
hub / github.com/openai/openai-node / startProxy

Function startProxy

ecosystem-tests/proxy.ts:4–27  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { connect } from 'net';
3
4async function startProxy() {
5 const proxy = createServer((_req, res) => {
6 res.end();
7 });
8
9 proxy.on('connect', (req, clientSocket, head) => {
10 const serverSocket = connect(443, 'api.openai.com', () => {
11 clientSocket.write(
12 'HTTP/1.1 200 Connection Established\r\n' + 'Proxy-agent: Node.js-Proxy\r\n' + '\r\n',
13 );
14 serverSocket.write(head);
15 serverSocket.pipe(clientSocket);
16 clientSocket.pipe(serverSocket);
17 });
18 });
19
20 await new Promise<void>((resolve) => proxy.listen(0, '127.0.0.1', resolve));
21
22 console.log(proxy.address()!.toString());
23
24 return () => {
25 proxy.close();
26 };
27}

Callers

nothing calls this directly

Calls 3

toStringMethod · 0.80
onMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected