Skip to content

refactor: improve migration #5040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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