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) + '...')