@@ -4,7 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite --host",
|
||||||
"build": "vue-tsc --noEmit && vite build",
|
"build": "vue-tsc --noEmit && vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -198,18 +198,10 @@ export const useSessionStore = defineStore('session', () => {
|
|||||||
// 根据当前页面协议动态生成 WebSocket URL,并移除硬编码的端口
|
// 根据当前页面协议动态生成 WebSocket URL,并移除硬编码的端口
|
||||||
// 假设 WebSocket 服务与 Web 服务在同一主机和端口上提供(通过反向代理)
|
// 假设 WebSocket 服务与 Web 服务在同一主机和端口上提供(通过反向代理)
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
// 移除端口 :3001,依赖反向代理或同源策略
|
// 使用 window.location.host,它包含主机名和端口(如果非默认)
|
||||||
// 如果 WebSocket 有特定路径 (例如 /ws),需要在这里添加
|
const wsHostAndPort = window.location.host;
|
||||||
// --- 修改:根据环境确定 WebSocket 主机 ---
|
// 假设 WebSocket 路径固定为 /ws/
|
||||||
let wsHost = window.location.hostname;
|
const wsUrl = `${protocol}//${wsHostAndPort}/ws/`;
|
||||||
if (window.location.hostname === 'localhost') {
|
|
||||||
wsHost = 'localhost:3001'; // 本地调试时硬编码
|
|
||||||
console.log('[SessionStore openNewSession] Using hardcoded localhost:3001 for WebSocket connection.');
|
|
||||||
} else {
|
|
||||||
console.log(`[SessionStore openNewSession] Using hostname: ${wsHost}`);
|
|
||||||
}
|
|
||||||
// --- 结束修改 ---
|
|
||||||
const wsUrl = `${protocol}//${wsHost}/ws/`; // 使用 wsHost 并添加 /ws/ 路径
|
|
||||||
console.log(`[SessionStore] Generated WebSocket URL: ${wsUrl}`); // 添加日志记录生成的 URL
|
console.log(`[SessionStore] Generated WebSocket URL: ${wsUrl}`); // 添加日志记录生成的 URL
|
||||||
wsManager.connect(wsUrl);
|
wsManager.connect(wsUrl);
|
||||||
console.log(`[SessionStore] 已为会话 ${newSessionId} 启动 WebSocket 连接。`);
|
console.log(`[SessionStore] 已为会话 ${newSessionId} 启动 WebSocket 连接。`);
|
||||||
@@ -398,19 +390,14 @@ export const useSessionStore = defineStore('session', () => {
|
|||||||
// 满足最高优先级:重连当前活动会话
|
// 满足最高优先级:重连当前活动会话
|
||||||
console.log(`[SessionStore] 活动会话 ${activeSessionId.value} 已断开或出错,尝试重连...`);
|
console.log(`[SessionStore] 活动会话 ${activeSessionId.value} 已断开或出错,尝试重连...`);
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
let wsHost = window.location.hostname;
|
// 使用 window.location.host
|
||||||
if (window.location.hostname === 'localhost') {
|
const wsHostAndPort = window.location.host;
|
||||||
wsHost = 'localhost:3001';
|
const wsUrl = `${protocol}//${wsHostAndPort}/ws/`;
|
||||||
console.log('[SessionStore handleConnectRequest] Using hardcoded localhost:3001 for WebSocket reconnect.');
|
|
||||||
} else {
|
|
||||||
console.log(`[SessionStore handleConnectRequest] Using hostname: ${wsHost}`);
|
|
||||||
}
|
|
||||||
const wsUrl = `${protocol}//${wsHost}/ws/`;
|
|
||||||
console.log(`[SessionStore handleConnectRequest] Generated WebSocket URL for reconnect: ${wsUrl}`);
|
console.log(`[SessionStore handleConnectRequest] Generated WebSocket URL for reconnect: ${wsUrl}`);
|
||||||
currentActiveSession.wsManager.connect(wsUrl);
|
currentActiveSession.wsManager.connect(wsUrl);
|
||||||
// 重连后,确保激活该会话(如果它不是活动会话)并导航
|
// 重连后,确保激活该会话(如果它不是活动会话)并导航
|
||||||
activateSession(activeSessionId.value); // 确保激活
|
activateSession(activeSessionId.value); // 确保激活
|
||||||
router.push({ name: 'Workspace' }); // +++ 添加跳转 +++
|
router.push({ name: 'Workspace' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,17 @@ export default defineConfig({
|
|||||||
// 可选:如果后端 API 路径没有 /api 前缀,可以在这里重写路径
|
// 可选:如果后端 API 路径没有 /api 前缀,可以在这里重写路径
|
||||||
// rewrite: (path) => path.replace(/^\/api/, '')
|
// rewrite: (path) => path.replace(/^\/api/, '')
|
||||||
},
|
},
|
||||||
// --- 新增开始 ---
|
|
||||||
// 将所有 /uploads 开头的请求也代理到后端服务器
|
// 将所有 /uploads 开头的请求也代理到后端服务器
|
||||||
'/uploads': {
|
'/uploads': {
|
||||||
target: 'http://localhost:3001', // 后端服务器地址
|
target: 'http://localhost:3001', // 后端服务器地址
|
||||||
changeOrigin: true, // 对于静态资源通常也建议开启
|
changeOrigin: true, // 对于静态资源通常也建议开启
|
||||||
// 通常不需要重写静态资源的路径
|
// 通常不需要重写静态资源的路径
|
||||||
|
},
|
||||||
|
'/ws': {
|
||||||
|
target: 'ws://localhost:3001', // 后端 WebSocket 服务器地址
|
||||||
|
ws: true,
|
||||||
|
changeOrigin: true,
|
||||||
}
|
}
|
||||||
// --- 新增结束 ---
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user