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();