Skip to content
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

feat(legacyCreateProxyMiddleware): adapter with v2 behaviour #754

Merged
merged 5 commits into from
Apr 18, 2022

Conversation

chimurai
Copy link
Owner

@chimurai chimurai commented Apr 17, 2022

Description

  • Add legacyCreateProxyMiddleware() to use v3 with v2 behaviour.
  • User's onError and on.error handler replaces default error handler.
  • MIGRATION.md

Motivation and Context

V3 introduces some breaking changes:
https://github.com/chimurai/http-proxy-middleware/milestone/2?closed=1

Allow users to upgrade to v3 with minimal changes.
After upgrading you can migrate deprecated functionality at your own pace.

How has this been tested?

webpack/webpack-dev-server@eea50f3 with http-proxy-middleware-v3.patch:

diff --git a/lib/Server.js b/lib/Server.js
index 9f374ba..c976f7c 100644
--- a/lib/Server.js
+++ b/lib/Server.js
@@ -31,7 +31,7 @@ const schema = require("./options.json");
 /** @typedef {import("bonjour-service").Bonjour} Bonjour */
 /** @typedef {import("bonjour-service").Service} BonjourOptions */
 /** @typedef {import("http-proxy-middleware").RequestHandler} RequestHandler */
-/** @typedef {import("http-proxy-middleware").Options} HttpProxyMiddlewareOptions */
+/** @typedef {import("http-proxy-middleware").LegacyOptions} HttpProxyMiddlewareOptions */
 /** @typedef {import("http-proxy-middleware").Filter} HttpProxyMiddlewareOptionsFilter */
 /** @typedef {import("serve-index").Options} ServeIndexOptions */
 /** @typedef {import("serve-static").ServeStaticOptions} ServeStaticOptions */
@@ -2120,7 +2120,7 @@ class Server {
     });
 
     if (this.options.proxy) {
-      const { createProxyMiddleware } = require("http-proxy-middleware");
+      const { legacyCreateProxyMiddleware: createProxyMiddleware } = require("http-proxy-middleware");
 
       /**
        * @param {ProxyConfigArrayItem} proxyConfig
diff --git a/test/e2e/allowed-hosts.test.js b/test/e2e/allowed-hosts.test.js
index aeb5b7a..8550be4 100644
--- a/test/e2e/allowed-hosts.test.js
+++ b/test/e2e/allowed-hosts.test.js
@@ -2,7 +2,7 @@
 
 const express = require("express");
 const webpack = require("webpack");
-const { createProxyMiddleware } = require("http-proxy-middleware");
+const { legacyCreateProxyMiddleware: createProxyMiddleware } = require("http-proxy-middleware");
 const Server = require("../../lib/Server");
 const config = require("../fixtures/client-config/webpack.config");
 const runBrowser = require("../helpers/run-browser");
diff --git a/test/e2e/web-socket-server-url.test.js b/test/e2e/web-socket-server-url.test.js
index a83f3d3..63d8392 100644
--- a/test/e2e/web-socket-server-url.test.js
+++ b/test/e2e/web-socket-server-url.test.js
@@ -2,7 +2,7 @@
 
 const express = require("express");
 const webpack = require("webpack");
-const { createProxyMiddleware } = require("http-proxy-middleware");
+const { legacyCreateProxyMiddleware: createProxyMiddleware } = require("http-proxy-middleware");
 const Server = require("../../lib/Server");
 const config = require("../fixtures/client-config/webpack.config");
 const runBrowser = require("../helpers/run-browser");

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@chimurai chimurai added this to the v3.0.0 milestone Apr 17, 2022
@chimurai chimurai changed the title feat(legacyCreateProxyMiddleware): adapter with legacy behaviour feat(legacyCreateProxyMiddleware): adapter with v2 behaviour Apr 17, 2022
@coveralls
Copy link

coveralls commented Apr 17, 2022

Coverage Status

Coverage increased (+0.3%) to 97.82% when pulling 4dc3e1d on legacy-adaptor into 397aed3 on v3.

@chimurai chimurai force-pushed the legacy-adaptor branch 2 times, most recently from 1dc79c5 to f996fe5 Compare April 17, 2022 21:04
@chimurai chimurai force-pushed the legacy-adaptor branch 2 times, most recently from 005682c to ea4187b Compare April 18, 2022 17:10
@chimurai chimurai merged commit cdfe934 into v3 Apr 18, 2022
@chimurai chimurai deleted the legacy-adaptor branch April 18, 2022 18:42
chimurai added a commit that referenced this pull request Apr 22, 2022
* fix(error event): user error event handler replaces default error response handler

* feat(legacyCreateProxyMiddleware): adapter with legacy behavior

* test(on.error): test custom error handler

* chore(typescript): deprecate LegacyOptions

* docs: minor doc improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants