code2024/bingo
0
1import Debug from 'debug'2 3const { fetch, setGlobalDispatcher, ProxyAgent } = require('undici')4const { HttpsProxyAgent } = require('https-proxy-agent')5const ws = require('ws')6 7const debug = Debug('bingo')8 9const httpProxy = process.env.http_proxy || process.env.HTTP_PROXY || process.env.https_proxy || process.env.HTTPS_PROXY;10let WebSocket = ws.WebSocket11 12if (httpProxy) {13 setGlobalDispatcher(new ProxyAgent(httpProxy))14 const agent = new HttpsProxyAgent(httpProxy)15 // @ts-ignore16 WebSocket = class extends ws.WebSocket {17 constructor(address: string | URL, options: typeof ws.WebSocket) {18 super(address, {19 ...options,20 agent,21 })22 }23 }24}25 26export default { fetch, WebSocket, debug }27 