Skip to content

Commit 9fbcc12

Browse files
committed
fix: upgradeing to websocket caused server crashed (closes chimurai#777)
1 parent 03239c7 commit 9fbcc12

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/http-proxy-middleware.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import * as PathRewriter from './path-rewriter';
88
import * as Router from './router';
99
import { Debug as debug } from './debug';
1010
import { getFunctionName } from './utils/function';
11+
import { getLogger } from './logger';
1112

1213
export class HttpProxyMiddleware {
1314
private wsInternalSubscribed = false;
1415
private serverOnCloseSubscribed = false;
1516
private proxyOptions: Options;
1617
private proxy: httpProxy;
1718
private pathRewriter;
19+
private logger = getLogger({ logger: console });
1820

1921
constructor(options: Options) {
2022
verifyConfig(options);
@@ -95,7 +97,10 @@ export class HttpProxyMiddleware {
9597
private handleUpgrade = async (req: Request, socket, head) => {
9698
if (this.shouldProxy(this.proxyOptions.pathFilter, req)) {
9799
const activeProxyOptions = await this.prepareProxyRequest(req);
98-
this.proxy.ws(req, socket, head, activeProxyOptions);
100+
this.proxy.ws(req, socket, head, activeProxyOptions, (err, req, socket) => {
101+
this.logger.error('[HPM] Upgrading to WebSocket Error:', err, req, socket);
102+
});
103+
99104
debug('server upgrade event received. Proxying WebSocket');
100105
}
101106
};

0 commit comments

Comments
 (0)