File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,19 @@ import { HttpCode } from "../common/http"
33
44export 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).
68proxy . 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). But writing out the code manually does not work
12+ // for regular requests thus the branching behavior.
13+ if ( typeof res . writeHead !== "undefined" ) {
14+ res . writeHead ( HttpCode . ServerError )
15+ res . end ( error . message )
16+ } else {
17+ res . end ( `HTTP/1.1 ${ HttpCode . ServerError } ${ error . message } \r\n\r\n` )
18+ }
919} )
1020
1121// Intercept the response to rewrite absolute redirects against the base path.
You can’t perform that action at this time.
0 commit comments