解决当使用https连接ws时报错

This commit is contained in:
srcrs 2023-07-28 02:38:53 +08:00
parent e1fa4f090c
commit 4516e72b5c

View File

@ -103,7 +103,8 @@
}; };
}, },
async created() { async created() {
const socket = new WebSocket("ws://" + window.location.host + "/ws"); const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
const socket = new WebSocket(protocol + window.location.host + "/ws");
socket.onmessage = event => { socket.onmessage = event => {
const feed = JSON.parse(event.data); const feed = JSON.parse(event.data);
this.feeds.push(feed); this.feeds.push(feed);