diff --git a/src/views/components/AppLogin.js b/src/views/components/AppLogin.js index 20cd062..3300af6 100644 --- a/src/views/components/AppLogin.js +++ b/src/views/components/AppLogin.js @@ -26,7 +26,7 @@ export default { }, async submitApi() { try { - let response = await window.http.get(`/app/login`) + let response = await window.http.get(`app/login`) let results = response.data.results; this.login_link = results.qr_link; this.login_duration_sec = results.qr_duration; diff --git a/src/views/components/AppLogout.js b/src/views/components/AppLogout.js index f0ed901..1e87c8f 100644 --- a/src/views/components/AppLogout.js +++ b/src/views/components/AppLogout.js @@ -15,7 +15,7 @@ export default { async submitApi() { try { - await http.get(`/app/logout`) + await http.get(`app/logout`) } catch (error) { if (error.response) { throw Error(error.response.data.message) diff --git a/src/views/index.html b/src/views/index.html index 564749d..e9708ab 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -180,6 +180,17 @@ }); } + const constructWebSocketURL = () => { + const protocol = location.protocol === 'https:' ? 'wss://' : 'ws://'; + const path = location.pathname + // Remove trailing slash + .replace(/\/+$/, '') + // Remove double slashes + .replace(/\/+/g, '/'); + + return `${protocol}${location.host}${path}/ws`; + }; + Vue.createApp({ components: { AppLogin, AppLoginWithCode, AppLogout, AppReconnect, @@ -203,8 +214,7 @@ }, mounted() { if (window["WebSocket"]) { - let wsType = location.protocol !== 'https:' ? 'ws://' : 'wss://'; - this.app_ws = new WebSocket(wsType + document.location.host + "/ws"); + this.app_ws = new WebSocket(constructWebSocketURL()); this.app_ws.onopen = (evt) => { this.app_ws.send(JSON.stringify({ @@ -213,6 +223,11 @@ })) }; + this.app_ws.onerror = (error) => { + console.error('WebSocket error:', error); + showErrorInfo('Connection error occurred. Please refresh the page.'); + }; + this.app_ws.onmessage = (evt) => { const message = JSON.parse(evt.data) switch (message.code) {