Skip to content

Commit

Permalink
feat: 支持代理ENDPOINT
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Sep 12, 2023
1 parent a5c24cc commit c3d6380
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bingo",
"version": "0.6.4",
"version": "0.7.0",
"private": true,
"scripts": {
"dev": "cross-env DEBUG=bingo* next dev --hostname 0.0.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export function createHeaders(cookies: Partial<{ [key: string]: string }>, type?
...cookies,
})
headers['x-forwarded-for'] = BING_IP || randomIP()
headers['x-ms-useragent'] = headers['x-ms-useragent'] || 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/Win32'
return headers
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const headers = createHeaders(req.cookies)
do {
headers['x-forwarded-for'] = headers['x-forwarded-for'] || randomIP()
const endpoints = [...(process.env.ENDPOINT || '').split(',').filter(Boolean), 'www.bing.com']
const endpoints = [req.headers['x-endpoint'], ...(process.env.ENDPOINT || '').split(',').filter(Boolean), 'www.bing.com']
const endpoint = endpoints[count % endpoints.length]
const { conversationId } = req.query
const query = conversationId ? new URLSearchParams({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/sydney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
debug(id, conversationContext, headers)
res.setHeader('Content-Type', 'text/stream; charset=UTF-8')

const ws = new WebSocket(`wss://${WS_ENDPOINT}/sydney/ChatHub`, {
const ws = new WebSocket(`wss://${req.headers['x-ws-endpoint'] || WS_ENDPOINT}/sydney/ChatHub`, {
headers: {
...headers,
'accept-language': 'zh-CN,zh;q=0.9',
Expand Down

0 comments on commit c3d6380

Please sign in to comment.