chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.76k stars 847 forks source link

feat(legacyCreateProxyMiddleware): adapter with v2 behaviour #754

Closed chimurai closed 2 years ago

chimurai commented 2 years ago

Description

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?

https://github.com/webpack/webpack-dev-server/commit/eea50f342e3090483f6da4932b84ed52bba44c58 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

Checklist:

coveralls commented 2 years ago

Coverage Status

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