Skip to content

Commit

Permalink
fix: issue vitejs#12664 avoid dev-server crash when ws proxy error
Browse files Browse the repository at this point in the history
  • Loading branch information
rawbin.zhang committed Apr 11, 2023
1 parent ad358da commit 8f9cdf8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/vite/src/node/server/middlewares/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ export function proxyMiddleware(
res.end()
}
})

proxy.on('proxyReqWs', (proxyReq, req, socket, options, head) => {
socket.on('error', (err) => {
config.logger.error(
`${colors.red(`ws proxy socket error:`)}\n${err.stack}`,
{
timestamp: true,
error: err,
},
)
})
})

// clone before saving because http-proxy mutates the options
proxies[context] = [proxy, { ...opts }]
})
Expand Down

0 comments on commit 8f9cdf8

Please sign in to comment.