diff --git a/lib/Server.js b/lib/Server.js index ab7b345960..1840b33e7c 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -2040,6 +2040,15 @@ class Server { if (proxyConfig.router) { return createProxyMiddleware(proxyConfig); } + + // TODO improve me after drop `bypass` to always generate error when configuration is bad + if (!proxyConfig.bypass) { + util.deprecate( + () => {}, + `Invalid proxy configuration:\n\n${JSON.stringify(proxyConfig, null, 2)}\n\nThe use of proxy object notation as proxy routes has been removed.\nPlease use the 'router' or 'context' options. Read more at https://github.com/chimurai/http-proxy-middleware/tree/v2.0.6#http-proxy-middleware-options`, + "DEP_WEBPACK_DEV_SERVER_PROXY_ROUTES_ARGUMENT", + )(); + } }; /** @@ -2090,12 +2099,15 @@ class Server { if (newProxyConfig !== proxyConfig) { proxyConfig = newProxyConfig; + const socket = req.socket != null ? req.socket : req.connection; // @ts-ignore const server = socket != null ? socket.server : null; + if (server) { server.removeAllListeners("close"); } + proxyMiddleware = /** @type {RequestHandler} */ (getProxyMiddleware(proxyConfig)); @@ -2110,7 +2122,7 @@ class Server { if (isByPassFuncDefined) { util.deprecate( () => {}, - "Using the 'bypass' option is deprecated. Please use the 'router' and 'context' options. Read more at https://github.com/chimurai/http-proxy-middleware/tree/v2.0.6#http-proxy-middleware-options", + "Using the 'bypass' option is deprecated. Please use the 'router' or 'context' options. Read more at https://github.com/chimurai/http-proxy-middleware/tree/v2.0.6#http-proxy-middleware-options", "DEP_WEBPACK_DEV_SERVER_PROXY_BYPASS_ARGUMENT", )(); } diff --git a/test/server/proxy-option.test.js b/test/server/proxy-option.test.js index 15ff236953..d894fdae08 100644 --- a/test/server/proxy-option.test.js +++ b/test/server/proxy-option.test.js @@ -238,7 +238,7 @@ describe("proxy option", () => { const lastCall = utilSpy.mock.calls[utilSpy.mock.calls.length - 1]; expect(lastCall[1]).toEqual( - "Using the 'bypass' option is deprecated. Please use the 'router' and 'context' options. Read more at https://github.com/chimurai/http-proxy-middleware/tree/v2.0.6#http-proxy-middleware-options", + "Using the 'bypass' option is deprecated. Please use the 'router' or 'context' options. Read more at https://github.com/chimurai/http-proxy-middleware/tree/v2.0.6#http-proxy-middleware-options", ); expect(lastCall[2]).toEqual( "DEP_WEBPACK_DEV_SERVER_PROXY_BYPASS_ARGUMENT",