From 7cba9ce231b9b1e31d73255f7d84bca00491f1b7 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sun, 18 Jul 2021 18:35:40 +0200 Subject: [PATCH 1/5] Remove debug spam --- server/server.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/server.js b/server/server.js index bd5894775..0d0ce51f1 100644 --- a/server/server.js +++ b/server/server.js @@ -50,7 +50,6 @@ let needSetup = false; version, }) - console.log('a user connected'); totalClient++; if (needSetup) { @@ -59,7 +58,6 @@ let needSetup = false; } socket.on('disconnect', () => { - console.log('user disconnected'); totalClient--; }); From 851ceef3d54c35cf2cf8e56e25a2803ff36192cb Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Sun, 18 Jul 2021 20:21:17 +0200 Subject: [PATCH 2/5] 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 3/5] 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 4/5] 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; From 77af41bfffac0ecf4de470d1521fd8de08bf1e33 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Mon, 19 Jul 2021 23:06:42 +0800 Subject: [PATCH 5/5] env default to production --- src/mixins/socket.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mixins/socket.js b/src/mixins/socket.js index cf7cb1218..6ad627244 100644 --- a/src/mixins/socket.js +++ b/src/mixins/socket.js @@ -35,8 +35,8 @@ export default { window.addEventListener('resize', this.onResize); let wsHost; - const env = process.env.NODE_ENV || 'development'; - if (env === "development") { + const env = process.env.NODE_ENV || "production"; + if (env === "development" || localStorage.dev === "dev") { wsHost = ":3001" } else { wsHost = ""