From fd22cc297d0df7c3a5c82fc5a510b1cb682f88fd Mon Sep 17 00:00:00 2001 From: pataar Date: Sun, 13 Feb 2022 18:40:49 +0100 Subject: [PATCH] refactor: make sure that port '80' and '443' are correctly passed through (#631) --- src/store/socket/index.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/store/socket/index.ts b/src/store/socket/index.ts index 8d9c24f96..b001d51d5 100644 --- a/src/store/socket/index.ts +++ b/src/store/socket/index.ts @@ -3,19 +3,37 @@ import { SocketState } from '@/store/socket/types' import { actions } from '@/store/socket/actions' import { mutations } from '@/store/socket/mutations' import { getters } from '@/store/socket/getters' -import {RootState} from '@/store/types' +import { RootState } from '@/store/types' export const getDefaultState = (): SocketState => { + let remoteMode: boolean + let hostname: string + let port: number + + if ( + document.location.hostname === 'my.mainsail.xyz' || + import.meta.env.VUE_APP_REMOTE_MODE + ) { + remoteMode = true + hostname = '' + port = 7125 + } else { + remoteMode = false + hostname = import.meta.env.VUE_APP_HOSTNAME as string || window.location.hostname + const defaultPort = window.location.port || (window.location.protocol === 'https:' ? 443 : 80) + port = import.meta.env.VUE_APP_PORT ? Number(import.meta.env.VUE_APP_PORT) : Number(defaultPort) + } + return { - remoteMode: import.meta.env.VUE_APP_REMOTE_MODE === true || (document.location.hostname === 'my.mainsail.xyz'), - hostname: (import.meta.env.VUE_APP_HOSTNAME as string) || ((import.meta.env.VUE_APP_REMOTE_MODE === true || document.location.hostname === 'my.mainsail.xyz') ? '' : window.location.hostname), - port: Number(import.meta.env.VUE_APP_PORT || (import.meta.env.VUE_APP_REMOTE_MODE === true || document.location.hostname === 'my.mainsail.xyz' ? 7125 : window.location.port)), + remoteMode, + hostname, + port, protocol: document.location.protocol === 'https:' ? 'wss' : 'ws', reconnectInterval: Number(import.meta.env.VUE_APP_RECONNECT_INTERVAL || 2000), isConnected: false, isConnecting: false, connectingFailed: false, - loadings: [] + loadings: [], } } @@ -27,5 +45,5 @@ export const socket: Module = { state, getters, actions, - mutations + mutations, }