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