Skip to content

Commit

Permalink
refactor: improve migration (#5040)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Feb 12, 2024
1 parent b453380 commit 4e4c97f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)();
}
};

/**
Expand Down Expand Up @@ -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));
Expand All @@ -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",
)();
}
Expand Down
2 changes: 1 addition & 1 deletion test/server/proxy-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4e4c97f

Please sign in to comment.