Skip to content

Commit 2cfc30a

Browse files
committed
fix(gpt-runner-web): server proxy throw error
1 parent d439ff7 commit 2cfc30a

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

packages/gpt-runner-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
{
3939
"type": "webview",
4040
"id": "gpt-runner.chatView",
41-
"name": "GPT Runner Chat"
41+
"name": ""
4242
}
4343
]
4444
},

packages/gpt-runner-web/client/src/router.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { FC } from 'react'
22
import { Suspense, useEffect } from 'react'
3-
import { Route, HashRouter as Router, Routes, useNavigate } from 'react-router-dom'
3+
import { Route, HashRouter as Router, Routes, useLocation, useNavigate } from 'react-router-dom'
44
import { VSCodeProgressRing } from '@vscode/webview-ui-toolkit/react'
55
import Home from './pages/home/index'
66
import Error404 from './pages/error/404'
@@ -10,9 +10,11 @@ import { globalConfig } from './helpers/global-config'
1010

1111
const HackRouter: FC = () => {
1212
const navigate = useNavigate()
13+
const location = useLocation()
1314

1415
useEffect(() => {
15-
navigate(globalConfig.initialRoutePath)
16+
if (location.pathname === '/')
17+
navigate(globalConfig.initialRoutePath)
1618
}, [])
1719

1820
return <></>

packages/gpt-runner-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"build:server": "unbuild",
5353
"dev": "pnpm dev:server & pnpm dev:client",
5454
"dev:client": "vite --config ./client/vite.config.ts",
55-
"dev:server": "esno server/index.ts",
55+
"dev:server": "pnpm esno server/index.ts",
5656
"start": "node dist/server.cjs",
5757
"stub": "unbuild --stub"
5858
},

packages/gpt-runner-web/server/src/proxy.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@ import { bootstrap } from 'global-agent'
22
import { ProxyAgent, setGlobalDispatcher } from 'undici'
33

44
// global proxy
5-
process.env.GLOBAL_AGENT_HTTP_PROXY = process.env.HTTP_PROXY || process.env.http_proxy
5+
process.env.GLOBAL_AGENT_HTTP_PROXY = ['HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY'].reduce((val, key) => {
6+
const upperKey = key.toUpperCase()
7+
const lowerKey = key.toLowerCase()
8+
const upperKeyValue = (process.env[upperKey] && process.env[upperKey] !== 'undefined') ? process.env[upperKey] || '' : ''
9+
const lowerKeyValue = process.env[lowerKey] && process.env[lowerKey] !== 'undefined' ? process.env[lowerKey] || '' : ''
10+
11+
return val || upperKeyValue || lowerKeyValue
12+
}, '')
613
bootstrap()
714

8-
setGlobalDispatcher(
9-
new ProxyAgent({
10-
uri: process.env.GLOBAL_AGENT_HTTP_PROXY!,
11-
connectTimeout: 60000,
12-
}),
13-
)
15+
if (process.env.GLOBAL_AGENT_HTTP_PROXY) {
16+
setGlobalDispatcher(
17+
new ProxyAgent({
18+
uri: process.env.GLOBAL_AGENT_HTTP_PROXY!,
19+
connectTimeout: 60000,
20+
}),
21+
)
22+
}

0 commit comments

Comments
 (0)