Skip to content

Commit 54df11d

Browse files
committed
refactor: remove API proxy route and simplify WebSocket connection by eliminating HTTPS-specific logic.
1 parent d72a820 commit 54df11d

3 files changed

Lines changed: 9 additions & 114 deletions

File tree

frontend/src/app/api/[...path]/route.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

frontend/src/config/env.ts

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,17 @@
33
* 用于 ModelScope 等不支持环境变量的部署环境
44
*/
55

6-
// 后端服务器地址(用于服务端代理)
7-
export const BACKEND_URL = 'http://83.229.126.150:3001'
8-
9-
/**
10-
* 检测是否在 HTTPS 环境
11-
*/
12-
function isHttpsEnv(): boolean {
13-
if (typeof window === 'undefined') return false
14-
return window.location.protocol === 'https:'
15-
}
16-
17-
/**
18-
* 获取 API URL
19-
* HTTPS 环境使用相对路径(走 Next.js 代理),HTTP 环境直接请求
20-
*/
21-
export function getApiUrl(): string {
22-
return isHttpsEnv() ? '' : BACKEND_URL
23-
}
6+
export const ENV_CONFIG = {
7+
// 后端 API 地址
8+
API_URL: 'https://turing.kinaz.me',
249

25-
/**
26-
* 获取 WebSocket URL
27-
* HTTPS 环境禁用(返回空),HTTP 环境直接连接
28-
*/
29-
export function getWsUrl(): string {
30-
return isHttpsEnv() ? '' : 'ws://83.229.126.150:3001'
31-
}
10+
// WebSocket 地址
11+
WS_URL: 'wss://turing.kinaz.me',
3212

33-
export const ENV_CONFIG = {
34-
// 视觉模型 API 配置(阶跃星辰)- 已经是 HTTPS,无需代理
13+
// 视觉模型 API 配置(阶跃星辰)
3514
VISION_API_URL: 'https://api.stepfun.com/v1',
3615
VISION_API_KEY: '4FlSdYVfkMrcVqaex9PXjLUOg8b3MazJ8GdY993DymL6sN3DwEYW39HwuowYdn7xC',
3716
VISION_MODEL: 'step-1o-turbo-vision',
38-
39-
// 兼容旧代码的 getter
40-
get API_URL() {
41-
return getApiUrl()
42-
},
43-
get WS_URL() {
44-
return getWsUrl()
45-
},
4617
} as const
4718

4819
export default ENV_CONFIG

frontend/src/hooks/useWebSocket.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,15 @@ export function useWebSocket({ url, roomId, enabled = true }: UseWebSocketOption
148148
useEffect(() => {
149149
if (!enabled || !roomId) return
150150

151-
// 检测是否在 HTTPS 环境
152-
const isHttps = typeof window !== 'undefined' && window.location.protocol === 'https:'
151+
const socketUrl = url || ENV_CONFIG.WS_URL
153152

154-
// HTTPS 环境使用相对路径(走代理),强制使用轮询模式
155-
// HTTP 环境直接连接后端,优先使用 WebSocket
156-
const socketUrl = isHttps ? '' : (url || ENV_CONFIG.WS_URL)
157-
const transports: ('websocket' | 'polling')[] = isHttps ? ['polling'] : ['websocket', 'polling']
158-
159-
console.log('[WS] Connecting to:', socketUrl || '(relative path)', 'Room:', roomId, 'Transports:', transports)
153+
console.log('[WS] Connecting to:', socketUrl, 'Room:', roomId)
160154

161155
socketRef.current = io(socketUrl, {
162-
transports,
156+
transports: ['websocket', 'polling'],
163157
reconnection: true,
164158
reconnectionDelay: 1000,
165159
reconnectionAttempts: 5,
166-
// HTTPS 环境下的额外配置
167-
...(isHttps && {
168-
path: '/socket.io',
169-
withCredentials: false,
170-
}),
171160
})
172161

173162
const socket = socketRef.current

0 commit comments

Comments
 (0)