Skip to content

Commit

Permalink
refactor: make sure that port '80' and '443' are correctly passed thr…
Browse files Browse the repository at this point in the history
…ough (#631)
  • Loading branch information
pataar authored Feb 13, 2022
1 parent 0cf8ba0 commit fd22cc2
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/store/socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
}
}

Expand All @@ -27,5 +45,5 @@ export const socket: Module<SocketState, RootState> = {
state,
getters,
actions,
mutations
mutations,
}

0 comments on commit fd22cc2

Please sign in to comment.