Skip to content

Commit cf32348

Browse files
committed
feat: remove deprecated bypass option from proxy configuration
1 parent b38824a commit cf32348

1 file changed

Lines changed: 6 additions & 53 deletions

File tree

lib/Server.js

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const os = require("node:os");
44
const path = require("node:path");
55
const url = require("node:url");
6-
const util = require("node:util");
76
const fs = require("graceful-fs");
87
const ipaddr = require("ipaddr.js");
98
const { validate } = require("schema-utils");
@@ -138,14 +137,7 @@ const schema = require("./options.json");
138137
*/
139138

140139
/**
141-
* @callback ByPass
142-
* @param {Request} req
143-
* @param {Response} res
144-
* @param {ProxyConfigArrayItem} proxyConfig
145-
*/
146-
147-
/**
148-
* @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem
140+
* @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem
149141
*/
150142

151143
/**
@@ -2131,10 +2123,9 @@ class Server {
21312123
* @returns {RequestHandler | undefined} request handler
21322124
*/
21332125
const getProxyMiddleware = (proxyConfig) => {
2134-
// It is possible to use the `bypass` method without a `target` or `router`.
2135-
// However, the proxy middleware has no use in this case, and will fail to instantiate.
21362126
if (proxyConfig.target) {
2137-
const context = proxyConfig.context || proxyConfig.path;
2127+
const context =
2128+
proxyConfig.context || proxyConfig.path || proxyConfig.pathFilter;
21382129

21392130
return createProxyMiddleware({
21402131
...proxyConfig,
@@ -2145,15 +2136,6 @@ class Server {
21452136
if (proxyConfig.router) {
21462137
return createProxyMiddleware(proxyConfig);
21472138
}
2148-
2149-
// TODO improve me after drop `bypass` to always generate error when configuration is bad
2150-
if (!proxyConfig.bypass) {
2151-
util.deprecate(
2152-
() => {},
2153-
`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`,
2154-
"DEP_WEBPACK_DEV_SERVER_PROXY_ROUTES_ARGUMENT",
2155-
)();
2156-
}
21572139
};
21582140

21592141
/**
@@ -2219,40 +2201,11 @@ class Server {
22192201
}
22202202
}
22212203

2222-
// - Check if we have a bypass function defined
2223-
// - In case the bypass function is defined we'll retrieve the
2224-
// bypassUrl from it otherwise bypassUrl would be null
2225-
// TODO remove in the next major in favor `context` and `router` options
2226-
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
2227-
if (isByPassFuncDefined) {
2228-
util.deprecate(
2229-
() => {},
2230-
"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",
2231-
"DEP_WEBPACK_DEV_SERVER_PROXY_BYPASS_ARGUMENT",
2232-
)();
2233-
}
2234-
const bypassUrl = isByPassFuncDefined
2235-
? await /** @type {ByPass} */ (proxyConfig.bypass)(
2236-
req,
2237-
res,
2238-
proxyConfig,
2239-
)
2240-
: null;
2241-
2242-
if (typeof bypassUrl === "boolean") {
2243-
// skip the proxy
2244-
res.statusCode = 404;
2245-
req.url = "";
2246-
next();
2247-
} else if (typeof bypassUrl === "string") {
2248-
// byPass to that url
2249-
req.url = bypassUrl;
2250-
next();
2251-
} else if (proxyMiddleware) {
2204+
if (proxyMiddleware) {
22522205
return proxyMiddleware(req, res, next);
2253-
} else {
2254-
next();
22552206
}
2207+
2208+
next();
22562209
};
22572210

22582211
middlewares.push({

0 commit comments

Comments
 (0)