修复HTTPS环境下WebSocket连接被拦截的问题

- WebSocket URL 根据页面协议自动选择 ws/wss
- 使用 window.location.host 替代硬编码端口,适配内网穿透代理场景

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
yml2213
2026-06-22 20:12:46 +08:00
co-authored by Claude Fable 5
parent 4522421293
commit e7edb56107
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -139,7 +139,7 @@ export default function LoginTasksPage() {
message.success(`已创建登录任务,共 ${result.count} 个账号`);
// 连接 WebSocket
const wsUrl = `ws://${window.location.hostname}:8000/api/login/ws/login/${result.batch_id}`;
const wsUrl = `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.host}/api/login/ws/login/${result.batch_id}`;
const ws = new WebSocket(wsUrl);
wsRef.current = ws;
setWsConnected(true);
+1 -1
View File
@@ -2,7 +2,7 @@ import { useEffect, useState, useRef } from 'react';
import { Form, Input, Switch, Button, Card, message, Row, Col, theme } from 'antd';
import { proxyApi } from '../api/modules';
const WS_BASE = `ws://${window.location.hostname}:8000`;
const WS_BASE = `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.host}`;
export default function ProxyPage() {
const { token } = theme.useToken();