From 832b0a28db265a010eb263ef5b338ac8cc3b38b4 Mon Sep 17 00:00:00 2001 From: Hendry Zheng Date: Mon, 1 May 2023 14:41:02 +0700 Subject: [PATCH] Fix:server on close on websocket only condition --- src/http-proxy-middleware.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/http-proxy-middleware.ts b/src/http-proxy-middleware.ts index 7f9bf07f..e63750d2 100644 --- a/src/http-proxy-middleware.ts +++ b/src/http-proxy-middleware.ts @@ -62,7 +62,8 @@ export class HttpProxyMiddleware { */ const server: https.Server = ((req.socket ?? req.connection) as any)?.server; - if (server && !this.serverOnCloseSubscribed) { + // subscribe to http 'close' event to close proxy socket on ws true + if (server && !this.serverOnCloseSubscribed && this.proxyOptions.ws === true) { server.on('close', () => { debug('server close signal received: closing proxy server'); this.proxy.close();