Skip to content

Commit

Permalink
Fix websocket address when not in production
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo Vuilliomenet committed Apr 27, 2023
1 parent 42d4374 commit d3922a6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions frontend/src/views/Conversations-index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down Expand Up @@ -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 = () => {
Expand Down

0 comments on commit d3922a6

Please sign in to comment.