Skip to content

Commit d725363

Browse files
committed
feat: remove deprecated bypass option from proxy configuration
1 parent e3aba33 commit d725363

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
/**
@@ -2148,10 +2140,9 @@ class Server {
21482140
* @returns {RequestHandler | undefined} request handler
21492141
*/
21502142
const getProxyMiddleware = (proxyConfig) => {
2151-
// It is possible to use the `bypass` method without a `target` or `router`.
2152-
// However, the proxy middleware has no use in this case, and will fail to instantiate.
21532143
if (proxyConfig.target) {
2154-
const context = proxyConfig.context || proxyConfig.path;
2144+
const context =
2145+
proxyConfig.context || proxyConfig.path || proxyConfig.pathFilter;
21552146

21562147
return createProxyMiddleware({
21572148
...proxyConfig,
@@ -2162,15 +2153,6 @@ class Server {
21622153
if (proxyConfig.router) {
21632154
return createProxyMiddleware(proxyConfig);
21642155
}
2165-
2166-
// TODO improve me after drop `bypass` to always generate error when configuration is bad
2167-
if (!proxyConfig.bypass) {
2168-
util.deprecate(
2169-
() => {},
2170-
`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`,
2171-
"DEP_WEBPACK_DEV_SERVER_PROXY_ROUTES_ARGUMENT",
2172-
)();
2173-
}
21742156
};
21752157

21762158
/**
@@ -2236,40 +2218,11 @@ class Server {
22362218
}
22372219
}
22382220

2239-
// - Check if we have a bypass function defined
2240-
// - In case the bypass function is defined we'll retrieve the
2241-
// bypassUrl from it otherwise bypassUrl would be null
2242-
// TODO remove in the next major in favor `context` and `router` options
2243-
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
2244-
if (isByPassFuncDefined) {
2245-
util.deprecate(
2246-
() => {},
2247-
"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",
2248-
"DEP_WEBPACK_DEV_SERVER_PROXY_BYPASS_ARGUMENT",
2249-
)();
2250-
}
2251-
const bypassUrl = isByPassFuncDefined
2252-
? await /** @type {ByPass} */ (proxyConfig.bypass)(
2253-
req,
2254-
res,
2255-
proxyConfig,
2256-
)
2257-
: null;
2258-
2259-
if (typeof bypassUrl === "boolean") {
2260-
// skip the proxy
2261-
res.statusCode = 404;
2262-
req.url = "";
2263-
next();
2264-
} else if (typeof bypassUrl === "string") {
2265-
// byPass to that url
2266-
req.url = bypassUrl;
2267-
next();
2268-
} else if (proxyMiddleware) {
2221+
if (proxyMiddleware) {
22692222
return proxyMiddleware(req, res, next);
2270-
} else {
2271-
next();
22722223
}
2224+
2225+
next();
22732226
};
22742227

22752228
middlewares.push({

0 commit comments

Comments
 (0)