Skip to content

Commit de2f7f5

Browse files
committed
refactor: deprecate bypass option in proxy (#4827)
1 parent 7bf31d9 commit de2f7f5

File tree

3 files changed

+569
-2314
lines changed

3 files changed

+569
-2314
lines changed

lib/Server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const os = require("os");
44
const path = require("path");
55
const url = require("url");
6+
const util = require("util");
67
const fs = require("graceful-fs");
78
const ipaddr = require("ipaddr.js");
89
const { validate } = require("schema-utils");
@@ -2063,6 +2064,13 @@ class Server {
20632064
// bypassUrl from it otherwise bypassUrl would be null
20642065
// TODO remove in the next major in favor `context` and `router` options
20652066
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
2067+
if (isByPassFuncDefined) {
2068+
util.deprecate(
2069+
() => {},
2070+
"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",
2071+
"DEP_WEBPACK_DEV_SERVER_PROXY_BYPASS_ARGUMENT"
2072+
)();
2073+
}
20662074
const bypassUrl = isByPassFuncDefined
20672075
? await /** @type {ByPass} */ (proxyConfig.bypass)(
20682076
req,

test/server/proxy-option.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const path = require("path");
4+
const util = require("util");
45
const request = require("supertest");
56
const express = require("express");
67
const bodyParser = require("body-parser");
@@ -214,6 +215,18 @@ describe("proxy option", () => {
214215
});
215216

216217
describe("bypass", () => {
218+
it("should log deprecation warning when bypass is used", async () => {
219+
const utilSpy = jest.spyOn(util, "deprecate");
220+
221+
expect(utilSpy.mock.calls[0][1]).toEqual(
222+
"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"
223+
);
224+
expect(utilSpy.mock.calls[0][2]).toEqual(
225+
"DEP_WEBPACK_DEV_SERVER_PROXY_BYPASS_ARGUMENT"
226+
);
227+
228+
utilSpy.mockRestore();
229+
});
217230
it("can rewrite a request path", async () => {
218231
const response = await req.get("/foo/bar.html");
219232

0 commit comments

Comments
 (0)