From 851ceef3d54c35cf2cf8e56e25a2803ff36192cb Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sun, 18 Jul 2021 20:21:17 +0200 Subject: [PATCH 1/3] Use `NODE_ENV` from Express and Socket.IO --- src/mixins/socket.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mixins/socket.js b/src/mixins/socket.js index f0a3b1a6a..be79e67b1 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -35,7 +35,8 @@ export default { window.addEventListener('resize', this.onResize); let wsHost; - if (localStorage.dev === "dev") { + const env = process.env.NODE_ENV || 'development'; + if (env === "development") { wsHost = ":3001" } else { wsHost = "" @@ -45,6 +46,10 @@ export default { transports: ['websocket'] }); + if (!socket.connected) { + console.error("Failed to connect to the backend") + } + socket.on('info', (info) => { this.info = info; }); From 59ebe134f177bfd0ab10bf0a1707125f6584ece7 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sun, 18 Jul 2021 20:46:45 +0200 Subject: [PATCH 2/3] Fix indentation --- src/mixins/socket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixins/socket.js b/src/mixins/socket.js index be79e67b1..441089924 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -163,7 +163,7 @@ export default { }, getSocket() { - return socket; + return socket; }, toastRes(res) { From 5bd3184ebf7c7732d46722acc8f5e8d362e07524 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sun, 18 Jul 2021 20:59:00 +0200 Subject: [PATCH 3/3] Use connect_error event --- src/mixins/socket.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mixins/socket.js b/src/mixins/socket.js index 441089924..cf7cb1218 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -46,9 +46,9 @@ export default { transports: ['websocket'] }); - if (!socket.connected) { - console.error("Failed to connect to the backend") - } + socket.on("connect_error", (err) => { + console.error(`Failed to connect to the backend. Socket.io connect_error: ${err.message}`); + }); socket.on('info', (info) => { this.info = info;