Skip to content

Commit

Permalink
fix: avoid dev-server crash when ws proxy error (#12829)
Browse files Browse the repository at this point in the history
  • Loading branch information
rawbin- committed May 8, 2023
1 parent d63129b commit 87e1f58
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/vite/src/node/server/middlewares/proxy.ts
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 87e1f58

Please sign in to comment.