File tree 1 file changed +11
-3
lines changed
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ function setupWebSocket(
101
101
}
102
102
103
103
console . log ( `[vite] server connection lost. polling for restart...` )
104
- await waitForSuccessfulPing ( hostAndPath )
104
+ await waitForSuccessfulPing ( protocol , hostAndPath )
105
105
location . reload ( )
106
106
} )
107
107
@@ -292,14 +292,22 @@ async function queueUpdate(p: Promise<(() => void) | undefined>) {
292
292
}
293
293
}
294
294
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
+
296
302
// eslint-disable-next-line no-constant-condition
297
303
while ( true ) {
298
304
try {
299
305
// A fetch on a websocket URL will return a successful promise with status 400,
300
306
// but will reject a networking error.
301
307
// 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
+ } )
303
311
break
304
312
} catch ( e ) {
305
313
// wait ms before attempting to ping again
You can’t perform that action at this time.
0 commit comments