From 50b3efec4c287edeaff184e583a2e2f9a0b4e640 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Wed, 3 Mar 2021 22:22:14 -0700 Subject: [PATCH] Move the prod and dev websocket URI to a config file. --- web/src/config.js | 11 +++++++++++ web/src/main.js | 11 ++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 web/src/config.js diff --git a/web/src/config.js b/web/src/config.js new file mode 100644 index 0000000..a887287 --- /dev/null +++ b/web/src/config.js @@ -0,0 +1,11 @@ +/** + * The URI that socket IO tries to connect to for websocket communication when + * built for production serving. + */ +export const websocket_uri = `/`; + +/** + * The websocket URI that Socket.IO tries to connect to when live-serving the + * site via webpack. + */ +export const dev_websocket_uri = 8081; \ No newline at end of file diff --git a/web/src/main.js b/web/src/main.js index 2f38b4d..40854df 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -4,17 +4,14 @@ import store from './store'; import io from 'socket.io-client'; import clipboard from "vue-clipboard2"; import VueSocketIOExt from 'vue-socket.io-extended'; +import {websocket_uri, dev_websocket_uri} from "./config"; Vue.config.productionTip = false; -// Get the URI for dev enfironments -let websocket_uri = `/`; -if (process.env.NODE_ENV === `development`) { - websocket_uri = `http://${window.location.hostname}:8081`; -}; - Vue.use(clipboard); -Vue.use(VueSocketIOExt, io(websocket_uri)); +Vue.use(VueSocketIOExt, io( + process.env.NODE_ENV === `development` ? websocket_uri : dev_websocket_uri +)); new Vue({ store,