File tree 1 file changed +12
-2
lines changed
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"
3
3
4
4
export const proxy = proxyServer . createProxyServer ( { } )
5
5
6
+ // The error handler catches when the proxy fails to connect (for example when
7
+ // there is nothing running on the target port).
6
8
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). 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
+ }
9
19
} )
10
20
11
21
// Intercept the response to rewrite absolute redirects against the base path.
You can’t perform that action at this time.
0 commit comments