From 499ed8b174640aa27eb4cba0cc7e1e54ecd323f7 Mon Sep 17 00:00:00 2001 From: ailuckly Date: Sat, 11 Apr 2026 23:11:27 +0800 Subject: [PATCH] fix: use HTTPS for API and WSS for WebSocket connections - Change VITE_APP_URL from http://:9009 to https:// in env files - Auto-detect ws/wss protocol based on page URL in aiChat.ts - Ensures getUserMedia works on HTTPS and WebSocket doesn't get blocked by mixed content policy --- vocata-web/.env.production | 2 +- vocata-web/.env.test | 2 +- vocata-web/src/utils/aiChat.ts | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/vocata-web/.env.production b/vocata-web/.env.production index f64a14f..deb3f6d 100644 --- a/vocata-web/.env.production +++ b/vocata-web/.env.production @@ -1,5 +1,5 @@ # 生产环境配置 # 注意:VITE_APP_URL 将在CI/CD构建时动态替换 -VITE_APP_URL=http://{{PRODUCTION_HOST}}:9009 +VITE_APP_URL=https://{{PRODUCTION_HOST}} VUE_APP_TITLE=VocaTa VITE_APP_ENV=production \ No newline at end of file diff --git a/vocata-web/.env.test b/vocata-web/.env.test index ce93b83..5881e29 100644 --- a/vocata-web/.env.test +++ b/vocata-web/.env.test @@ -1,5 +1,5 @@ # 测试环境配置 # 注意:VITE_APP_URL 将在CI/CD构建时动态替换 -VITE_APP_URL=http://{{STAGING_HOST}}:9009 +VITE_APP_URL=https://{{STAGING_HOST}} VUE_APP_TITLE=VocaTa - 测试环境 VITE_APP_ENV=test \ No newline at end of file diff --git a/vocata-web/src/utils/aiChat.ts b/vocata-web/src/utils/aiChat.ts index 9cc114f..9820200 100644 --- a/vocata-web/src/utils/aiChat.ts +++ b/vocata-web/src/utils/aiChat.ts @@ -105,7 +105,11 @@ export class VocaTaWebSocketClient { return } - const wsUrl = `ws://${import.meta.env.VITE_APP_URL.replace('http://', '')}/ws/chat/${this.conversationUuid}?token=${encodeURIComponent(token)}` + const appUrl = import.meta.env.VITE_APP_URL || window.location.origin + const isSecure = appUrl.startsWith('https') + const wsProtocol = isSecure ? 'wss' : 'ws' + const host = appUrl.replace(/^https?:\/\//, '') + const wsUrl = `${wsProtocol}://${host}/ws/chat/${this.conversationUuid}?token=${encodeURIComponent(token)}` console.log('🔌 尝试连接WebSocket:', wsUrl) console.log('🔐 使用Token:', token.substring(0, 20) + '...')