From d3922a6798c62f00067dcbb46f885b569dc1a48e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Vuilliomenet?= Date: Thu, 27 Apr 2023 17:20:11 +0200 Subject: [PATCH] Fix websocket address when not in production --- frontend/src/views/Conversations-index.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/frontend/src/views/Conversations-index.vue b/frontend/src/views/Conversations-index.vue index 40a7ca1..4b9a095 100644 --- a/frontend/src/views/Conversations-index.vue +++ b/frontend/src/views/Conversations-index.vue @@ -7,11 +7,10 @@ import moment from "moment"; import "@/assets/shake.css"; const API_URL = import.meta.env.VITE_API_URL; -//const WS_HOST = import.meta.env.VITE_WEBSOCKET_HOST; +const WS_HOST_LOCAL = "127.0.0.1:8000"; const route = useRoute(); const router = useRouter(); -//const errors = ref(null); const loggedUserId = ref(-1); const message = ref(""); @@ -42,11 +41,15 @@ const fetchMessages = async (id) => { }; const startWebSocket = async (id) => { - var ws_scheme = window.location.protocol === "https:" ? "wss" : "ws"; + let scheme = "ws"; + let host = WS_HOST_LOCAL; - webSocket = new WebSocket( - ws_scheme + "://" + window.location.host + "/ws/chat/" + id + "/" - ); + if (window.location.protocol === "https:") { + scheme = "wss"; + host = window.location.host; + } + + webSocket = new WebSocket(scheme + "://" + host + "/ws/chat/" + id + "/"); // receive message webSocket.onmessage = () => {