File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ function setupWebSocket(
101101 }
102102
103103 console . log ( `[vite] server connection lost. polling for restart...` )
104- await waitForSuccessfulPing ( hostAndPath )
104+ await waitForSuccessfulPing ( protocol , hostAndPath )
105105 location . reload ( )
106106 } )
107107
@@ -292,14 +292,22 @@ async function queueUpdate(p: Promise<(() => void) | undefined>) {
292292 }
293293}
294294
295- async function waitForSuccessfulPing ( hostAndPath : string , ms = 1000 ) {
295+ async function waitForSuccessfulPing (
296+ socketProtocol : string ,
297+ hostAndPath : string ,
298+ ms = 1000
299+ ) {
300+ const pingHostProtocol = socketProtocol === 'wss' ? 'https' : 'http'
301+
296302 // eslint-disable-next-line no-constant-condition
297303 while ( true ) {
298304 try {
299305 // A fetch on a websocket URL will return a successful promise with status 400,
300306 // but will reject a networking error.
301307 // When running on middleware mode, it returns status 426, and an cors error happens if mode is not no-cors
302- await fetch ( `${ location . protocol } //${ hostAndPath } ` , { mode : 'no-cors' } )
308+ await fetch ( `${ pingHostProtocol } ://${ hostAndPath } ` , {
309+ mode : 'no-cors'
310+ } )
303311 break
304312 } catch ( e ) {
305313 // wait ms before attempting to ping again
You can’t perform that action at this time.
0 commit comments