Skip to content

Commit

Permalink
fix: fix proxy bug
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Jul 5, 2024
1 parent 7138c67 commit 5755213
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/enable-global-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { bootstrap } from 'global-agent'
import { ProxyAgent, setGlobalDispatcher } from 'undici'

import { logger } from './logger'

function getDefaultProxyUrl() {
let proxyUrl = ''

Expand All @@ -25,11 +27,16 @@ function getDefaultProxyUrl() {
}

export const enableGlobalProxy = () => {
const proxyUrl = getDefaultProxyUrl()

bootstrap()
const dispatcher = new ProxyAgent(proxyUrl)
setGlobalDispatcher(dispatcher)

return dispatcher
try {
const proxyUrl = getDefaultProxyUrl()

bootstrap()

if (proxyUrl) {
const dispatcher = new ProxyAgent(proxyUrl)
setGlobalDispatcher(dispatcher)
}
} catch (err) {
logger.log('Failed to enable global proxy', err)
}
}

0 comments on commit 5755213

Please sign in to comment.