http-proxy-middleware 3.0.0-beta.0 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -22
- package/dist/configuration.d.ts +1 -1
- package/dist/get-plugins.d.ts +1 -1
- package/dist/handlers/fix-request-body.d.ts +4 -2
- package/dist/handlers/response-interceptor.d.ts +3 -2
- package/dist/http-proxy-middleware.d.ts +2 -2
- package/dist/index.d.ts +4 -2
- package/dist/legacy/create-proxy-middleware.d.ts +5 -3
- package/dist/legacy/options-adapter.d.ts +1 -1
- package/dist/legacy/types.d.ts +3 -1
- package/dist/path-filter.d.ts +4 -2
- package/dist/plugins/default/logger-plugin.js +2 -1
- package/dist/types.d.ts +58 -23
- package/package.json +31 -45
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# http-proxy-middleware
|
|
2
2
|
|
|
3
|
-
[](https://coveralls.io/r/chimurai/http-proxy-middleware)
|
|
5
|
-
[](https://www.npmjs.com/package/http-proxy-middleware)
|
|
3
|
+
[](https://github.com/chimurai/http-proxy-middleware/actions/workflows/ci.yml?query=branch%3Amaster)
|
|
4
|
+
[](https://coveralls.io/r/chimurai/http-proxy-middleware)
|
|
5
|
+
[](https://security.snyk.io/package/npm/http-proxy-middleware)
|
|
6
|
+
[](https://www.npmjs.com/package/http-proxy-middleware)
|
|
7
7
|
|
|
8
8
|
Node.js proxying made simple. Configure proxy middleware with ease for [connect](https://github.com/senchalabs/connect), [express](https://github.com/expressjs/express), [next.js](https://github.com/vercel/next.js) and [many more](#compatible-servers).
|
|
9
9
|
|
|
10
|
-
Powered by the popular Nodejitsu [`http-proxy`](https://github.com/
|
|
10
|
+
Powered by the popular Nodejitsu [`http-proxy`](https://github.com/http-party/node-http-proxy). [](https://github.com/http-party/node-http-proxy)
|
|
11
11
|
|
|
12
12
|
## ⚠️ Note <!-- omit in toc -->
|
|
13
13
|
|
|
@@ -45,7 +45,7 @@ app.use(
|
|
|
45
45
|
app.listen(3000);
|
|
46
46
|
|
|
47
47
|
// proxy and change the base path from "/api" to "/secret"
|
|
48
|
-
// http://
|
|
48
|
+
// http://127.0.0.1:3000/api/foo/bar -> http://www.example.org/secret/foo/bar
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
@@ -67,7 +67,7 @@ app.use(
|
|
|
67
67
|
app.listen(3000);
|
|
68
68
|
|
|
69
69
|
// proxy and keep the same base path "/api"
|
|
70
|
-
// http://
|
|
70
|
+
// http://127.0.0.1:3000/api/foo/bar -> http://www.example.org/api/foo/bar
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
_All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#options) can be used, along with some extra `http-proxy-middleware` [options](#options).
|
|
@@ -81,7 +81,7 @@ _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#option
|
|
|
81
81
|
- [Express Server Example](#express-server-example)
|
|
82
82
|
- [app.use(path, proxy)](#appusepath-proxy)
|
|
83
83
|
- [Options](#options)
|
|
84
|
-
- [`pathFilter` (string, []string, glob, []glob, function)](#pathfilter-string-string-glob-glob-function)
|
|
84
|
+
- [`pathFilter` (string, \[\]string, glob, \[\]glob, function)](#pathfilter-string-string-glob-glob-function)
|
|
85
85
|
- [`pathRewrite` (object/function)](#pathrewrite-objectfunction)
|
|
86
86
|
- [`router` (object/function)](#router-objectfunction)
|
|
87
87
|
- [`plugins` (Array)](#plugins-array)
|
|
@@ -93,6 +93,7 @@ _All_ `http-proxy` [options](https://github.com/nodejitsu/node-http-proxy#option
|
|
|
93
93
|
- [External WebSocket upgrade](#external-websocket-upgrade)
|
|
94
94
|
- [Intercept and manipulate requests](#intercept-and-manipulate-requests)
|
|
95
95
|
- [Intercept and manipulate responses](#intercept-and-manipulate-responses)
|
|
96
|
+
- [Node.js 17+: ECONNREFUSED issue with IPv6 and localhost (#705)](#nodejs-17-econnrefused-issue-with-ipv6-and-localhost-705)
|
|
96
97
|
- [Debugging](#debugging)
|
|
97
98
|
- [Working examples](#working-examples)
|
|
98
99
|
- [Recipes](#recipes)
|
|
@@ -140,15 +141,12 @@ const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
|
140
141
|
|
|
141
142
|
const app = express();
|
|
142
143
|
|
|
143
|
-
//
|
|
144
|
-
/** @type {import('http-proxy-middleware/dist/types').
|
|
145
|
-
const
|
|
144
|
+
// create the proxy
|
|
145
|
+
/** @type {import('http-proxy-middleware/dist/types').RequestHandler<express.Request, express.Response>} */
|
|
146
|
+
const exampleProxy = createProxyMiddleware({
|
|
146
147
|
target: 'http://www.example.org/api', // target host with the same base path
|
|
147
148
|
changeOrigin: true, // needed for virtual hosted sites
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// create the proxy
|
|
151
|
-
const exampleProxy = createProxyMiddleware(options);
|
|
149
|
+
});
|
|
152
150
|
|
|
153
151
|
// mount `exampleProxy` in web server
|
|
154
152
|
app.use('/api', exampleProxy);
|
|
@@ -257,22 +255,22 @@ Re-target `option.target` for specific requests.
|
|
|
257
255
|
// Use `host` and/or `path` to match requests. First match will be used.
|
|
258
256
|
// The order of the configuration matters.
|
|
259
257
|
router: {
|
|
260
|
-
'integration.localhost:3000' : 'http://
|
|
261
|
-
'staging.localhost:3000' : 'http://
|
|
262
|
-
'localhost:3000/api' : 'http://
|
|
263
|
-
'/rest' : 'http://
|
|
258
|
+
'integration.localhost:3000' : 'http://127.0.0.1:8001', // host only
|
|
259
|
+
'staging.localhost:3000' : 'http://127.0.0.1:8002', // host only
|
|
260
|
+
'localhost:3000/api' : 'http://127.0.0.1:8003', // host + path
|
|
261
|
+
'/rest' : 'http://127.0.0.1:8004' // path only
|
|
264
262
|
}
|
|
265
263
|
|
|
266
264
|
// Custom router function (string target)
|
|
267
265
|
router: function(req) {
|
|
268
|
-
return 'http://
|
|
266
|
+
return 'http://127.0.0.1:8004';
|
|
269
267
|
}
|
|
270
268
|
|
|
271
269
|
// Custom router function (target object)
|
|
272
270
|
router: function(req) {
|
|
273
271
|
return {
|
|
274
272
|
protocol: 'https:', // The : is required
|
|
275
|
-
host: '
|
|
273
|
+
host: '127.0.0.1',
|
|
276
274
|
port: 8004
|
|
277
275
|
};
|
|
278
276
|
}
|
|
@@ -488,7 +486,7 @@ The following options are provided by the underlying [http-proxy](https://github
|
|
|
488
486
|
req,
|
|
489
487
|
res,
|
|
490
488
|
{
|
|
491
|
-
target: 'http://
|
|
489
|
+
target: 'http://127.0.0.1:4003/',
|
|
492
490
|
buffer: streamify(req.rawBody),
|
|
493
491
|
},
|
|
494
492
|
next
|
|
@@ -573,6 +571,21 @@ const proxy = createProxyMiddleware({
|
|
|
573
571
|
|
|
574
572
|
Check out [interception recipes](https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/response-interceptor.md#readme) for more examples.
|
|
575
573
|
|
|
574
|
+
## Node.js 17+: ECONNREFUSED issue with IPv6 and localhost ([#705](https://github.com/chimurai/http-proxy-middleware/issues/705))
|
|
575
|
+
|
|
576
|
+
Node.js 17+ no longer prefers IPv4 over IPv6 for DNS lookups.
|
|
577
|
+
E.g. It's **not** guaranteed that `localhost` will be resolved to `127.0.0.1` – it might just as well be `::1` (or some other IP address).
|
|
578
|
+
|
|
579
|
+
If your target server only accepts IPv4 connections, trying to proxy to `localhost` will fail if resolved to `::1` (IPv6).
|
|
580
|
+
|
|
581
|
+
Ways to solve it:
|
|
582
|
+
|
|
583
|
+
- Change `target: "http://localhost"` to `target: "http://127.0.0.1"` (IPv4).
|
|
584
|
+
- Change the target server to (also) accept IPv6 connections.
|
|
585
|
+
- Add this flag when running `node`: `node index.js --dns-result-order=ipv4first`. (Not recommended.)
|
|
586
|
+
|
|
587
|
+
> Note: There’s a thing called [Happy Eyeballs](https://en.wikipedia.org/wiki/Happy_Eyeballs) which means connecting to both IPv4 and IPv6 in parallel, which Node.js doesn’t have, but explains why for example `curl` can connect.
|
|
588
|
+
|
|
576
589
|
## Debugging
|
|
577
590
|
|
|
578
591
|
Configure the `DEBUG` environment variable enable debug logging.
|
package/dist/configuration.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Options } from './types';
|
|
2
|
-
export declare function verifyConfig(options: Options): void;
|
|
2
|
+
export declare function verifyConfig<TReq, TRes>(options: Options<TReq, TRes>): void;
|
package/dist/get-plugins.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Options, Plugin } from './types';
|
|
2
|
-
export declare function getPlugins(options: Options): Plugin[];
|
|
2
|
+
export declare function getPlugins<TReq, TRes>(options: Options<TReq, TRes>): Plugin<TReq, TRes>[];
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type * as http from 'http';
|
|
3
|
-
|
|
3
|
+
export declare type BodyParserLikeRequest = http.IncomingMessage & {
|
|
4
|
+
body: any;
|
|
5
|
+
};
|
|
4
6
|
/**
|
|
5
7
|
* Fix proxied body if bodyParser is involved.
|
|
6
8
|
*/
|
|
7
|
-
export declare function fixRequestBody(proxyReq: http.ClientRequest, req:
|
|
9
|
+
export declare function fixRequestBody<TReq = http.IncomingMessage>(proxyReq: http.ClientRequest, req: TReq): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type * as http from 'http';
|
|
3
|
-
declare type Interceptor = (buffer: Buffer, proxyRes:
|
|
4
|
+
declare type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: TReq, req: TReq, res: TRes) => Promise<Buffer | string>;
|
|
4
5
|
/**
|
|
5
6
|
* Intercept responses from upstream.
|
|
6
7
|
* Automatically decompress (deflate, gzip, brotli).
|
|
@@ -8,5 +9,5 @@ declare type Interceptor = (buffer: Buffer, proxyRes: http.IncomingMessage, req:
|
|
|
8
9
|
*
|
|
9
10
|
* NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
|
|
10
11
|
*/
|
|
11
|
-
export declare function responseInterceptor(interceptor: Interceptor): (proxyRes:
|
|
12
|
+
export declare function responseInterceptor<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse>(interceptor: Interceptor<TReq, TRes>): (proxyRes: TReq, req: TReq, res: TRes) => Promise<void>;
|
|
12
13
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { RequestHandler, Options } from './types';
|
|
2
|
-
export declare class HttpProxyMiddleware {
|
|
2
|
+
export declare class HttpProxyMiddleware<TReq, TRes> {
|
|
3
3
|
private wsInternalSubscribed;
|
|
4
4
|
private serverOnCloseSubscribed;
|
|
5
5
|
private proxyOptions;
|
|
6
6
|
private proxy;
|
|
7
7
|
private pathRewriter;
|
|
8
|
-
constructor(options: Options);
|
|
8
|
+
constructor(options: Options<TReq, TRes>);
|
|
9
9
|
middleware: RequestHandler;
|
|
10
10
|
private registerPlugins;
|
|
11
11
|
private catchUpgradeRequest;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Options, RequestHandler, NextFunction } from './types';
|
|
3
|
+
import type * as http from 'http';
|
|
4
|
+
export declare function createProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext>;
|
|
3
5
|
export * from './handlers';
|
|
4
6
|
export type { Filter, Options, RequestHandler } from './types';
|
|
5
7
|
/**
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Filter, RequestHandler } from '../types';
|
|
2
3
|
import { LegacyOptions } from './types';
|
|
4
|
+
import type * as http from 'http';
|
|
3
5
|
/**
|
|
4
6
|
* @deprecated
|
|
5
7
|
* This function is deprecated and will be removed in a future version.
|
|
6
8
|
*
|
|
7
9
|
* Use {@link createProxyMiddleware} instead.
|
|
8
10
|
*/
|
|
9
|
-
export declare function legacyCreateProxyMiddleware(shortHand: string): RequestHandler
|
|
10
|
-
export declare function legacyCreateProxyMiddleware(legacyOptions: LegacyOptions): RequestHandler
|
|
11
|
-
export declare function legacyCreateProxyMiddleware(legacyContext: Filter
|
|
11
|
+
export declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(shortHand: string): RequestHandler<TReq, TRes>;
|
|
12
|
+
export declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(legacyOptions: LegacyOptions<TReq, TRes>): RequestHandler<TReq, TRes>;
|
|
13
|
+
export declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(legacyContext: Filter<TReq>, legacyOptions: LegacyOptions<TReq, TRes>): RequestHandler<TReq, TRes>;
|
|
@@ -3,4 +3,4 @@ import { LegacyOptions } from './types';
|
|
|
3
3
|
/**
|
|
4
4
|
* Convert {@link LegacyOptions legacy Options} to new {@link Options}
|
|
5
5
|
*/
|
|
6
|
-
export declare function legacyOptionsAdapter(legacyContext: Filter | LegacyOptions, legacyOptions: LegacyOptions): Options
|
|
6
|
+
export declare function legacyOptionsAdapter<TReq, TRes>(legacyContext: Filter<TReq> | LegacyOptions<TReq, TRes>, legacyOptions: LegacyOptions<TReq, TRes>): Options<TReq, TRes>;
|
package/dist/legacy/types.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type * as http from 'http';
|
|
1
3
|
import { Options } from '..';
|
|
2
4
|
/**
|
|
3
5
|
* @deprecated
|
|
4
6
|
*
|
|
5
7
|
* Will be removed in a future version.
|
|
6
8
|
*/
|
|
7
|
-
export interface LegacyOptions extends Options {
|
|
9
|
+
export interface LegacyOptions<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends Options<TReq, TRes> {
|
|
8
10
|
/**
|
|
9
11
|
* @deprecated
|
|
10
12
|
* Use `on.error` instead.
|
package/dist/path-filter.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Filter } from './types';
|
|
3
|
+
import type * as http from 'http';
|
|
4
|
+
export declare function matchPathFilter<TReq = http.IncomingMessage>(pathFilter: Filter<TReq>, uri: string, req: http.IncomingMessage): boolean;
|
|
@@ -23,7 +23,8 @@ const loggerPlugin = (proxyServer, options) => {
|
|
|
23
23
|
proxyServer.on('proxyRes', (proxyRes, req, res) => {
|
|
24
24
|
var _a;
|
|
25
25
|
// BrowserSync uses req.originalUrl
|
|
26
|
-
|
|
26
|
+
// Next.js doesn't have req.baseUrl
|
|
27
|
+
const originalUrl = (_a = req.originalUrl) !== null && _a !== void 0 ? _a : `${req.baseUrl || ''}${req.url}`;
|
|
27
28
|
const exchange = `[HPM] ${req.method} ${originalUrl} -> ${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path} [${proxyRes.statusCode}]`;
|
|
28
29
|
logger.info(exchange);
|
|
29
30
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -3,40 +3,56 @@
|
|
|
3
3
|
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
|
|
4
4
|
*/
|
|
5
5
|
/// <reference types="node" />
|
|
6
|
+
/// <reference types="node" />
|
|
7
|
+
/// <reference types="node" />
|
|
6
8
|
import type * as http from 'http';
|
|
7
9
|
import type * as httpProxy from 'http-proxy';
|
|
8
10
|
import type * as net from 'net';
|
|
9
|
-
export declare type Request<T = http.IncomingMessage> = T;
|
|
10
|
-
export declare type Response<T = http.ServerResponse> = T;
|
|
11
11
|
export declare type NextFunction<T = (err?: any) => void> = T;
|
|
12
|
-
export interface RequestHandler {
|
|
13
|
-
(req:
|
|
14
|
-
upgrade?: (req:
|
|
12
|
+
export interface RequestHandler<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction> {
|
|
13
|
+
(req: TReq, res: TRes, next?: TNext): void | Promise<void>;
|
|
14
|
+
upgrade?: (req: http.IncomingMessage, socket: net.Socket, head: any) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare type Filter<TReq = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
|
|
17
|
+
export interface Plugin<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
|
18
|
+
(proxyServer: httpProxy<TReq, TRes>, options: Options<TReq, TRes>): void;
|
|
15
19
|
}
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
proxyReqWs?: httpProxy.ProxyReqWsCallback;
|
|
22
|
-
proxyRes?: httpProxy.ProxyResCallback;
|
|
20
|
+
export interface OnProxyEvent<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
|
21
|
+
error?: httpProxy.ErrorCallback<Error, TReq, TRes>;
|
|
22
|
+
proxyReq?: httpProxy.ProxyReqCallback<http.ClientRequest, TReq, TRes>;
|
|
23
|
+
proxyReqWs?: httpProxy.ProxyReqWsCallback<http.ClientRequest, TReq>;
|
|
24
|
+
proxyRes?: httpProxy.ProxyResCallback<TReq, TRes>;
|
|
23
25
|
open?: httpProxy.OpenCallback;
|
|
24
|
-
close?: httpProxy.CloseCallback
|
|
25
|
-
start?: httpProxy.StartCallback
|
|
26
|
-
end?: httpProxy.EndCallback
|
|
27
|
-
econnreset?: httpProxy.EconnresetCallback
|
|
28
|
-
}
|
|
26
|
+
close?: httpProxy.CloseCallback<TReq>;
|
|
27
|
+
start?: httpProxy.StartCallback<TReq, TRes>;
|
|
28
|
+
end?: httpProxy.EndCallback<TReq, TRes>;
|
|
29
|
+
econnreset?: httpProxy.EconnresetCallback<Error, TReq, TRes>;
|
|
30
|
+
}
|
|
29
31
|
export declare type Logger = Pick<Console, 'info' | 'warn' | 'error'>;
|
|
30
|
-
export interface Options extends httpProxy.ServerOptions {
|
|
32
|
+
export interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends httpProxy.ServerOptions {
|
|
31
33
|
/**
|
|
32
34
|
* Narrow down requests to proxy or not.
|
|
33
35
|
* Filter on {@link http.IncomingMessage.url `pathname`} which is relative to the proxy's "mounting" point in the server.
|
|
34
36
|
* Or use the {@link http.IncomingMessage `req`} object for more complex filtering.
|
|
37
|
+
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathFilter.md
|
|
38
|
+
* @since v3.0.0
|
|
39
|
+
*/
|
|
40
|
+
pathFilter?: Filter<TReq>;
|
|
41
|
+
/**
|
|
42
|
+
* Modify request paths before requests are send to the target.
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* createProxyMiddleware({
|
|
46
|
+
* pathRewrite: {
|
|
47
|
+
* '^/api/old-path': '/api/new-path', // rewrite path
|
|
48
|
+
* }
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
|
|
35
52
|
*/
|
|
36
|
-
pathFilter?: Filter;
|
|
37
53
|
pathRewrite?: {
|
|
38
54
|
[regexp: string]: string;
|
|
39
|
-
} | ((path: string, req:
|
|
55
|
+
} | ((path: string, req: TReq) => string) | ((path: string, req: TReq) => Promise<string>);
|
|
40
56
|
/**
|
|
41
57
|
* Access the internal http-proxy server instance to customize behavior
|
|
42
58
|
*
|
|
@@ -50,12 +66,15 @@ export interface Options extends httpProxy.ServerOptions {
|
|
|
50
66
|
* }]
|
|
51
67
|
* });
|
|
52
68
|
* ```
|
|
69
|
+
* @link https://github.com/chimurai/http-proxy-middleware#plugins-array
|
|
70
|
+
* @since v3.0.0
|
|
53
71
|
*/
|
|
54
|
-
plugins?: Plugin[];
|
|
72
|
+
plugins?: Plugin<TReq, TRes>[];
|
|
55
73
|
/**
|
|
56
74
|
* Eject pre-configured plugins.
|
|
57
75
|
* NOTE: register your own error handlers to prevent server from crashing.
|
|
58
76
|
*
|
|
77
|
+
* @link https://github.com/chimurai/http-proxy-middleware#ejectplugins-boolean-default-false
|
|
59
78
|
* @since v3.0.0
|
|
60
79
|
*/
|
|
61
80
|
ejectPlugins?: boolean;
|
|
@@ -72,11 +91,25 @@ export interface Options extends httpProxy.ServerOptions {
|
|
|
72
91
|
* }
|
|
73
92
|
* });
|
|
74
93
|
* ```
|
|
94
|
+
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/proxy-events.md
|
|
95
|
+
* @since v3.0.0
|
|
96
|
+
*/
|
|
97
|
+
on?: OnProxyEvent<TReq, TRes>;
|
|
98
|
+
/**
|
|
99
|
+
* Dynamically set the {@link Options.target `options.target`}.
|
|
100
|
+
* @example
|
|
101
|
+
* ```js
|
|
102
|
+
* createProxyMiddleware({
|
|
103
|
+
* router: async (req) => {
|
|
104
|
+
* return 'http://127:0.0.1:3000';
|
|
105
|
+
* }
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md
|
|
75
109
|
*/
|
|
76
|
-
on?: OnProxyEvent;
|
|
77
110
|
router?: {
|
|
78
111
|
[hostOrPath: string]: httpProxy.ServerOptions['target'];
|
|
79
|
-
} | ((req:
|
|
112
|
+
} | ((req: TReq) => httpProxy.ServerOptions['target']) | ((req: TReq) => Promise<httpProxy.ServerOptions['target']>);
|
|
80
113
|
/**
|
|
81
114
|
* Log information from http-proxy-middleware
|
|
82
115
|
* @example
|
|
@@ -85,6 +118,8 @@ export interface Options extends httpProxy.ServerOptions {
|
|
|
85
118
|
* logger: console
|
|
86
119
|
* });
|
|
87
120
|
* ```
|
|
121
|
+
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/logger.md
|
|
122
|
+
* @since v3.0.0
|
|
88
123
|
*/
|
|
89
124
|
logger?: Logger | any;
|
|
90
125
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-proxy-middleware",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "The one-liner node.js proxy middleware for connect, express, next.js and more",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,21 +8,18 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"clean": "rm -rf dist
|
|
11
|
+
"clean": "rm -rf dist coverage tsconfig.tsbuildinfo .eslintcache",
|
|
12
12
|
"lint": "yarn prettier && yarn eslint",
|
|
13
13
|
"lint:fix": "yarn prettier:fix && yarn eslint:fix",
|
|
14
|
-
"eslint": "eslint '{src,test}/**/*.ts'",
|
|
14
|
+
"eslint": "eslint '{src,test}/**/*.ts' --cache",
|
|
15
15
|
"eslint:fix": "yarn eslint --fix",
|
|
16
16
|
"prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
|
|
17
17
|
"prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
|
|
18
|
-
"
|
|
19
|
-
"build": "tsc",
|
|
20
|
-
"pretest": "yarn build",
|
|
18
|
+
"build": "tsc --build",
|
|
21
19
|
"test": "jest",
|
|
22
|
-
"
|
|
23
|
-
"coverage": "jest --coverage --coverageReporters=lcov",
|
|
20
|
+
"coverage": "jest --coverage",
|
|
24
21
|
"prepare": "husky install",
|
|
25
|
-
"prepack": "yarn
|
|
22
|
+
"prepack": "yarn clean && yarn test && yarn build",
|
|
26
23
|
"spellcheck": "npx --yes cspell --show-context --show-suggestions '**/*.*'"
|
|
27
24
|
},
|
|
28
25
|
"repository": {
|
|
@@ -54,56 +51,45 @@
|
|
|
54
51
|
},
|
|
55
52
|
"homepage": "https://github.com/chimurai/http-proxy-middleware#readme",
|
|
56
53
|
"devDependencies": {
|
|
57
|
-
"@commitlint/cli": "
|
|
58
|
-
"@commitlint/config-conventional": "
|
|
54
|
+
"@commitlint/cli": "17.4.4",
|
|
55
|
+
"@commitlint/config-conventional": "17.4.4",
|
|
59
56
|
"@types/debug": "4.1.7",
|
|
60
|
-
"@types/express": "4.17.
|
|
57
|
+
"@types/express": "4.17.17",
|
|
61
58
|
"@types/is-glob": "4.0.2",
|
|
62
|
-
"@types/jest": "
|
|
59
|
+
"@types/jest": "29.4.0",
|
|
63
60
|
"@types/micromatch": "4.0.2",
|
|
64
|
-
"@types/node": "
|
|
61
|
+
"@types/node": "18.14.5",
|
|
65
62
|
"@types/supertest": "2.0.12",
|
|
66
|
-
"@types/ws": "8.5.
|
|
67
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
68
|
-
"@typescript-eslint/parser": "5.
|
|
69
|
-
"body-parser": "1.20.
|
|
70
|
-
"browser-sync": "2.
|
|
63
|
+
"@types/ws": "8.5.4",
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "5.54.0",
|
|
65
|
+
"@typescript-eslint/parser": "5.54.0",
|
|
66
|
+
"body-parser": "1.20.2",
|
|
67
|
+
"browser-sync": "2.28.1",
|
|
71
68
|
"connect": "3.7.0",
|
|
72
|
-
"eslint": "8.
|
|
73
|
-
"eslint-config-prettier": "8.
|
|
74
|
-
"eslint-plugin-prettier": "4.
|
|
75
|
-
"express": "4.
|
|
69
|
+
"eslint": "8.35.0",
|
|
70
|
+
"eslint-config-prettier": "8.6.0",
|
|
71
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
72
|
+
"express": "4.18.2",
|
|
76
73
|
"get-port": "5.1.1",
|
|
77
|
-
"husky": "
|
|
78
|
-
"jest": "
|
|
79
|
-
"lint-staged": "
|
|
80
|
-
"mockttp": "
|
|
81
|
-
"open": "8.4.
|
|
82
|
-
"prettier": "2.
|
|
83
|
-
"supertest": "6.
|
|
84
|
-
"ts-jest": "
|
|
85
|
-
"typescript": "4.
|
|
86
|
-
"ws": "8.
|
|
74
|
+
"husky": "8.0.3",
|
|
75
|
+
"jest": "29.4.3",
|
|
76
|
+
"lint-staged": "13.1.2",
|
|
77
|
+
"mockttp": "3.7.0",
|
|
78
|
+
"open": "8.4.2",
|
|
79
|
+
"prettier": "2.8.4",
|
|
80
|
+
"supertest": "6.3.3",
|
|
81
|
+
"ts-jest": "29.0.5",
|
|
82
|
+
"typescript": "4.9.5",
|
|
83
|
+
"ws": "8.12.1"
|
|
87
84
|
},
|
|
88
85
|
"dependencies": {
|
|
89
|
-
"@types/http-proxy": "^1.17.
|
|
86
|
+
"@types/http-proxy": "^1.17.10",
|
|
90
87
|
"debug": "^4.3.4",
|
|
91
88
|
"http-proxy": "^1.18.1",
|
|
92
89
|
"is-glob": "^4.0.1",
|
|
93
90
|
"is-plain-obj": "^3.0.0",
|
|
94
91
|
"micromatch": "^4.0.5"
|
|
95
92
|
},
|
|
96
|
-
"peerDependencies": {
|
|
97
|
-
"@types/express": "^4.17.13"
|
|
98
|
-
},
|
|
99
|
-
"peerDependenciesMeta": {
|
|
100
|
-
"@types/express": {
|
|
101
|
-
"optional": true
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
"resolutions": {
|
|
105
|
-
"browser-sync/portscanner": "2.2.0"
|
|
106
|
-
},
|
|
107
93
|
"engines": {
|
|
108
94
|
"node": ">=12.0.0"
|
|
109
95
|
},
|