Team Ai
Apppublic

Staticmaple/NEWBING

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
node.ts27 linesDownload Raw Back to isomorphic
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