From c46542bee0fba5854c1b131188b12ffdfa2c8a4a Mon Sep 17 00:00:00 2001 From: John Smith Date: Sun, 13 Oct 2019 17:02:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9HTTPS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/Room.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/views/Room.vue b/frontend/src/views/Room.vue index 3b87b79..d672b50 100644 --- a/frontend/src/views/Room.vue +++ b/frontend/src/views/Room.vue @@ -76,8 +76,10 @@ export default { } }, wsConnect() { + const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws' // 开发时使用localhost:12450 - const url = process.env.NODE_ENV === 'development' ? 'ws://localhost:12450/chat' : `ws://${window.location.host}/chat` + const host = process.env.NODE_ENV === 'development' ? 'localhost:12450' : window.location.host + const url = `${protocol}://${host}/chat` this.websocket = new WebSocket(url) this.websocket.onopen = this.onWsOpen this.websocket.onclose = this.onWsClose