From d3ce48507c9b21e20c8c7ed190100863a6a2beab Mon Sep 17 00:00:00 2001 From: rowan Date: Tue, 23 Jun 2020 21:32:45 +1000 Subject: [PATCH] feat: change websocket protocol based on location --- src/client/client.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index 26a8004e01480d..d4176cb21661a7 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -50,7 +50,8 @@ console.log('[vite] connecting...') declare var __VUE_HMR_RUNTIME__: HMRRuntime -const socket = new WebSocket(`ws://${location.hostname}:24678`) +const socketProtocol = location.protocol === 'https:' ? 'wss' : 'ws' +const socket = new WebSocket(`${socketProtocol}://${location.hostname}:24678`) function warnFailedFetch(err: Error, path: string | string[]) { if (!err.message.match('fetch')) { @@ -139,7 +140,7 @@ socket.addEventListener('message', async ({ data }) => { socket.addEventListener('close', () => { console.log(`[vite] server connection lost. polling for restart...`) setInterval(() => { - new WebSocket(`ws://${location.hostname}:24678`).addEventListener( + new WebSocket(`${socketProtocol}://${location.hostname}:24678`).addEventListener( 'open', () => { location.reload()