File tree 2 files changed +15
-0
lines changed
2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -321,6 +321,11 @@ async function waitForSuccessfulPing(
321
321
try {
322
322
await fetch ( `${ pingHostProtocol } ://${ hostAndPath } ` , {
323
323
mode : 'no-cors' ,
324
+ headers : {
325
+ // Custom headers won't be included in a request with no-cors so (ab)use one of the
326
+ // safelisted headers to identify the ping request
327
+ Accept : 'text/x-vite-ping' ,
328
+ } ,
324
329
} )
325
330
return true
326
331
} catch { }
Original file line number Diff line number Diff line change @@ -608,6 +608,16 @@ export async function _createServer(
608
608
// open in editor support
609
609
middlewares . use ( '/__open-in-editor' , launchEditorMiddleware ( ) )
610
610
611
+ // ping request handler
612
+ // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
613
+ middlewares . use ( function viteHMRPingMiddleware ( req , res , next ) {
614
+ if ( req . headers [ 'accept' ] === 'text/x-vite-ping' ) {
615
+ res . writeHead ( 204 ) . end ( )
616
+ } else {
617
+ next ( )
618
+ }
619
+ } )
620
+
611
621
// serve static files under /public
612
622
// this applies before the transform middleware so that these files are served
613
623
// as-is without transforms.
You can’t perform that action at this time.
0 commit comments