Skip to content

Commit 01f35c1

Browse files
snitin315alexander-akait
authored andcommitted
refactor: deprecate bypass option in proxy (#4827)
1 parent 504b464 commit 01f35c1

File tree

3 files changed

+428
-2191
lines changed

3 files changed

+428
-2191
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");
@@ -2084,6 +2085,13 @@ class Server {
20842085
// bypassUrl from it otherwise bypassUrl would be null
20852086
// TODO remove in the next major in favor `context` and `router` options
20862087
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
2088+
if (isByPassFuncDefined) {
2089+
util.deprecate(
2090+
() => {},
2091+
"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",
2092+
"DEP_WEBPACK_DEV_SERVER_PROXY_BYPASS_ARGUMENT"
2093+
)();
2094+
}
20872095
const bypassUrl = isByPassFuncDefined
20882096
? await /** @type {ByPass} */ (proxyConfig.bypass)(
20892097
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)