Skip to content

Commit a4bdf6c

Browse files
committed
Fix proxy error on web sockets
Fixes #6088.
1 parent a9d61da commit a4bdf6c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/node/proxy.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { HttpCode } from "../common/http"
33

44
export const proxy = proxyServer.createProxyServer({})
55

6+
// The error handler catches when the proxy fails to connect (for example when
7+
// there is nothing running on the target port).
68
proxy.on("error", (error, _, res) => {
7-
res.writeHead(HttpCode.ServerError)
8-
res.end(error.message)
9+
// This could be for either a web socket or a regular request. Despite what
10+
// the types say, writeHead() will not exist on web socket requests (nor will
11+
// status() from Express) so write out the code manually.
12+
res.end(`HTTP/1.1 ${HttpCode.ServerError} ${error.message}\r\n\r\n`)
913
})
1014

1115
// Intercept the response to rewrite absolute redirects against the base path.

0 commit comments

Comments
 (0)