Skip to content

Commit

Permalink
Fix HMR server when WebSocket proxy is running on the same port (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bminer committed Jan 4, 2024
1 parent f8076f1 commit a35e573
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/reporters/dev-server/src/HMRServer.js
Expand Up @@ -86,7 +86,14 @@ export default class HMRServer {
} else {
this.options.addMiddleware?.((req, res) => this.handle(req, res));
}
this.wss = new WebSocket.Server({server});
this.wss = new WebSocket.Server({noServer: true});
server.on('upgrade', (req, ws, head) => {
let {pathname} = url.parse(req.originalUrl || req.url);
if (pathname != null && pathname.startsWith(HMR_ENDPOINT)) {
const emitConnection = this.wss.emit.bind(this.wss, 'connection');
this.wss.handleUpgrade(req, ws, head, emitConnection);
}
})

this.wss.on('connection', ws => {
if (this.unresolvedError) {
Expand Down

0 comments on commit a35e573

Please sign in to comment.