@rspack/core 2.0.0 → 2.0.2
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/compiled/http-proxy-middleware/index.d.ts +229 -391
- package/compiled/http-proxy-middleware/package.json +1 -1
- package/compiled/watchpack/index.d.ts +2 -218
- package/compiled/watchpack/index.js +1387 -939
- package/compiled/watchpack/package.json +8 -1
- package/compiled/watchpack/types/DirectoryWatcher.d.ts +333 -0
- package/compiled/watchpack/types/LinkResolver.d.ts +10 -0
- package/compiled/watchpack/types/getWatcherManager.d.ts +62 -0
- package/compiled/watchpack/types/index.d.ts +261 -0
- package/compiled/watchpack/types/reducePlan.d.ts +34 -0
- package/compiled/watchpack/types/watchEventSource.d.ts +53 -0
- package/compiled/watchpack/types/watchpack.d.ts +2 -0
- package/dist/Compilation.d.ts +2 -2
- package/dist/builtin-plugin/rsc/RscServerPlugin.d.ts +1 -1
- package/dist/builtin-plugin/rsc/index.d.ts +4 -4
- package/dist/index.js +34 -25
- package/dist/stats/statsFactoryUtils.d.ts +3 -3
- package/package.json +7 -8
|
@@ -1,250 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import * as http from 'node:http';
|
|
2
|
+
import http__default, { ServerResponse, IncomingMessage } from 'node:http';
|
|
3
|
+
import * as net from 'node:net';
|
|
4
|
+
import net__default, { Socket } from 'node:net';
|
|
5
|
+
import http2, { Http2ServerResponse, Http2ServerRequest } from 'node:http2';
|
|
6
|
+
import { EventEmitter } from 'node:events';
|
|
7
|
+
import * as stream from 'node:stream';
|
|
7
8
|
|
|
8
9
|
interface ProxyTargetDetailed {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
host?: string;
|
|
11
|
+
port?: number | string;
|
|
12
|
+
protocol?: string;
|
|
13
|
+
hostname?: string;
|
|
14
|
+
socketPath?: string;
|
|
15
|
+
key?: string;
|
|
16
|
+
passphrase?: string;
|
|
17
|
+
pfx?: Buffer | string;
|
|
18
|
+
cert?: string;
|
|
19
|
+
ca?: string;
|
|
20
|
+
ciphers?: string;
|
|
21
|
+
secureProtocol?: string;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* @param options Config object passed to the proxy
|
|
85
|
-
* @returns Proxy object with handlers for `ws` and `web` requests
|
|
86
|
-
*/
|
|
87
|
-
// tslint:disable:no-unnecessary-generics
|
|
88
|
-
static createServer<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse>(
|
|
89
|
-
options?: Server.ServerOptions,
|
|
90
|
-
): Server<TIncomingMessage, TServerResponse>;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Creates the proxy server with specified options.
|
|
94
|
-
* @param options Config object passed to the proxy
|
|
95
|
-
* @returns Proxy object with handlers for `ws` and `web` requests
|
|
96
|
-
*/
|
|
97
|
-
// tslint:disable:no-unnecessary-generics
|
|
98
|
-
static createProxy<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse>(
|
|
99
|
-
options?: Server.ServerOptions,
|
|
100
|
-
): Server<TIncomingMessage, TServerResponse>;
|
|
101
|
-
|
|
102
|
-
addListener(event: string, listener: () => void): this;
|
|
103
|
-
on(event: string, listener: () => void): this;
|
|
104
|
-
on(event: "error", listener: Server.ErrorCallback<Error, TIncomingMessage, TServerResponse>): this;
|
|
105
|
-
on(event: "start", listener: Server.StartCallback<TIncomingMessage, TServerResponse>): this;
|
|
106
|
-
on(
|
|
107
|
-
event: "proxyReq",
|
|
108
|
-
listener: Server.ProxyReqCallback<http.ClientRequest, TIncomingMessage, TServerResponse>,
|
|
109
|
-
): this;
|
|
110
|
-
on(event: "proxyRes", listener: Server.ProxyResCallback<TIncomingMessage, TServerResponse>): this;
|
|
111
|
-
on(event: "proxyReqWs", listener: Server.ProxyReqWsCallback<http.ClientRequest, TIncomingMessage>): this;
|
|
112
|
-
on(event: "econnreset", listener: Server.EconnresetCallback<Error, TIncomingMessage, TServerResponse>): this;
|
|
113
|
-
on(event: "end", listener: Server.EndCallback<TIncomingMessage, TServerResponse>): this;
|
|
114
|
-
on(event: "open", listener: Server.OpenCallback): this;
|
|
115
|
-
on(event: "close", listener: Server.CloseCallback<TIncomingMessage>): this;
|
|
116
|
-
|
|
117
|
-
once(event: string, listener: () => void): this;
|
|
118
|
-
once(event: "error", listener: Server.ErrorCallback<Error, TIncomingMessage, TServerResponse>): this;
|
|
119
|
-
once(event: "start", listener: Server.StartCallback<TIncomingMessage, TServerResponse>): this;
|
|
120
|
-
once(
|
|
121
|
-
event: "proxyReq",
|
|
122
|
-
listener: Server.ProxyReqCallback<http.ClientRequest, TIncomingMessage, TServerResponse>,
|
|
123
|
-
): this;
|
|
124
|
-
once(event: "proxyRes", listener: Server.ProxyResCallback<TIncomingMessage, TServerResponse>): this;
|
|
125
|
-
once(event: "proxyReqWs", listener: Server.ProxyReqWsCallback<http.ClientRequest, TIncomingMessage>): this;
|
|
126
|
-
once(event: "econnreset", listener: Server.EconnresetCallback<Error, TIncomingMessage, TServerResponse>): this;
|
|
127
|
-
once(event: "end", listener: Server.EndCallback<TIncomingMessage, TServerResponse>): this;
|
|
128
|
-
once(event: "open", listener: Server.OpenCallback): this;
|
|
129
|
-
once(event: "close", listener: Server.CloseCallback<TIncomingMessage>): this;
|
|
130
|
-
removeListener(event: string, listener: () => void): this;
|
|
131
|
-
removeAllListeners(event?: string): this;
|
|
132
|
-
getMaxListeners(): number;
|
|
133
|
-
setMaxListeners(n: number): this;
|
|
134
|
-
listeners(event: string): Array<() => void>;
|
|
135
|
-
emit(event: string, ...args: any[]): boolean;
|
|
136
|
-
listenerCount(type: string): number;
|
|
23
|
+
type ProxyTarget = string | URL | ProxyTargetDetailed;
|
|
24
|
+
interface ProxyServerOptions {
|
|
25
|
+
/** URL string to be parsed. */
|
|
26
|
+
target?: ProxyTarget;
|
|
27
|
+
/** URL string to be parsed. */
|
|
28
|
+
forward?: ProxyTarget;
|
|
29
|
+
/** Object to be passed to http(s).request. */
|
|
30
|
+
agent?: any;
|
|
31
|
+
/** Enable HTTP/2 listener, default is `false` */
|
|
32
|
+
http2?: boolean;
|
|
33
|
+
/** Object to be passed to https.createServer()
|
|
34
|
+
* or http2.createSecureServer() if the `http2` option is enabled
|
|
35
|
+
*/
|
|
36
|
+
ssl?: any;
|
|
37
|
+
/** If you want to proxy websockets. */
|
|
38
|
+
ws?: boolean;
|
|
39
|
+
/** Adds x- forward headers. */
|
|
40
|
+
xfwd?: boolean;
|
|
41
|
+
/** Verify SSL certificate. */
|
|
42
|
+
secure?: boolean;
|
|
43
|
+
/** Explicitly specify if we are proxying to another proxy. */
|
|
44
|
+
toProxy?: boolean;
|
|
45
|
+
/** Specify whether you want to prepend the target's path to the proxy path. */
|
|
46
|
+
prependPath?: boolean;
|
|
47
|
+
/** Specify whether you want to ignore the proxy path of the incoming request. */
|
|
48
|
+
ignorePath?: boolean;
|
|
49
|
+
/** Local interface string to bind for outgoing connections. */
|
|
50
|
+
localAddress?: string;
|
|
51
|
+
/** Changes the origin of the host header to the target URL. */
|
|
52
|
+
changeOrigin?: boolean;
|
|
53
|
+
/** specify whether you want to keep letter case of response header key */
|
|
54
|
+
preserveHeaderKeyCase?: boolean;
|
|
55
|
+
/** Basic authentication i.e. 'user:password' to compute an Authorization header. */
|
|
56
|
+
auth?: string;
|
|
57
|
+
/** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
|
|
58
|
+
hostRewrite?: string;
|
|
59
|
+
/** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
|
|
60
|
+
autoRewrite?: boolean;
|
|
61
|
+
/** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
|
|
62
|
+
protocolRewrite?: string;
|
|
63
|
+
/** Rewrites domain of set-cookie headers. */
|
|
64
|
+
cookieDomainRewrite?: false | string | {
|
|
65
|
+
[oldDomain: string]: string;
|
|
66
|
+
};
|
|
67
|
+
/** Rewrites path of set-cookie headers. Default: false */
|
|
68
|
+
cookiePathRewrite?: false | string | {
|
|
69
|
+
[oldPath: string]: string;
|
|
70
|
+
};
|
|
71
|
+
/** Object with extra headers to be added to target requests. */
|
|
72
|
+
headers?: {
|
|
73
|
+
[header: string]: string;
|
|
74
|
+
};
|
|
75
|
+
/** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
|
|
76
|
+
proxyTimeout?: number;
|
|
77
|
+
/** Timeout (in milliseconds) for incoming requests */
|
|
78
|
+
timeout?: number;
|
|
79
|
+
/** If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event */
|
|
80
|
+
selfHandleResponse?: boolean;
|
|
81
|
+
/** Follow HTTP redirects from target. `true` = max 5 hops; number = custom max. */
|
|
82
|
+
followRedirects?: boolean | number;
|
|
83
|
+
/** Buffer */
|
|
84
|
+
buffer?: stream.Stream;
|
|
137
85
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
headers?: { [header: string]: string } | undefined;
|
|
184
|
-
/** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
|
|
185
|
-
proxyTimeout?: number | undefined;
|
|
186
|
-
/** Timeout (in milliseconds) for incoming requests */
|
|
187
|
-
timeout?: number | undefined;
|
|
188
|
-
/** Specify whether you want to follow redirects. Default: false */
|
|
189
|
-
followRedirects?: boolean | undefined;
|
|
190
|
-
/** If set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the proxyRes event */
|
|
191
|
-
selfHandleResponse?: boolean | undefined;
|
|
192
|
-
/** Buffer */
|
|
193
|
-
buffer?: stream.Stream | undefined;
|
|
194
|
-
/** Explicitly set the method type of the ProxyReq */
|
|
195
|
-
method?: string | undefined;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
type StartCallback<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> = (
|
|
199
|
-
req: TIncomingMessage,
|
|
200
|
-
res: TServerResponse,
|
|
201
|
-
target: ProxyTargetUrl,
|
|
202
|
-
) => void;
|
|
203
|
-
type ProxyReqCallback<
|
|
204
|
-
TClientRequest = http.ClientRequest,
|
|
205
|
-
TIncomingMessage = http.IncomingMessage,
|
|
206
|
-
TServerResponse = http.ServerResponse,
|
|
207
|
-
> = (proxyReq: TClientRequest, req: TIncomingMessage, res: TServerResponse, options: ServerOptions) => void;
|
|
208
|
-
type ProxyResCallback<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> = (
|
|
209
|
-
proxyRes: TIncomingMessage,
|
|
210
|
-
req: TIncomingMessage,
|
|
211
|
-
res: TServerResponse,
|
|
212
|
-
) => void;
|
|
213
|
-
type ProxyReqWsCallback<TClientRequest = http.ClientRequest, TIncomingMessage = http.IncomingMessage> = (
|
|
214
|
-
proxyReq: TClientRequest,
|
|
215
|
-
req: TIncomingMessage,
|
|
216
|
-
socket: net.Socket,
|
|
217
|
-
options: ServerOptions,
|
|
218
|
-
head: any,
|
|
219
|
-
) => void;
|
|
220
|
-
type EconnresetCallback<
|
|
221
|
-
TError = Error,
|
|
222
|
-
TIncomingMessage = http.IncomingMessage,
|
|
223
|
-
TServerResponse = http.ServerResponse,
|
|
224
|
-
> = (
|
|
225
|
-
err: TError,
|
|
226
|
-
req: TIncomingMessage,
|
|
227
|
-
res: TServerResponse,
|
|
228
|
-
target: ProxyTargetUrl,
|
|
229
|
-
) => void;
|
|
230
|
-
type EndCallback<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> = (
|
|
231
|
-
req: TIncomingMessage,
|
|
232
|
-
res: TServerResponse,
|
|
233
|
-
proxyRes: TIncomingMessage,
|
|
234
|
-
) => void;
|
|
235
|
-
type OpenCallback = (proxySocket: net.Socket) => void;
|
|
236
|
-
type CloseCallback<TIncomingMessage = http.IncomingMessage> = (
|
|
237
|
-
proxyRes: TIncomingMessage,
|
|
238
|
-
proxySocket: net.Socket,
|
|
239
|
-
proxyHead: any,
|
|
240
|
-
) => void;
|
|
241
|
-
type ErrorCallback<TError = Error, TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse> =
|
|
242
|
-
(
|
|
243
|
-
err: TError,
|
|
244
|
-
req: TIncomingMessage,
|
|
245
|
-
res: TServerResponse | net.Socket,
|
|
246
|
-
target?: ProxyTargetUrl,
|
|
247
|
-
) => void;
|
|
86
|
+
type ResOfType<T extends "web" | "ws"> = T extends "ws" ? T extends "web" ? ServerResponse | Http2ServerResponse | Socket : Socket : T extends "web" ? ServerResponse | Http2ServerResponse : never;
|
|
87
|
+
type ProxyMiddleware<T extends ServerResponse | Http2ServerResponse | Socket> = (req: IncomingMessage | Http2ServerRequest, res: T, opts: ProxyServerOptions & {
|
|
88
|
+
target: URL | ProxyTargetDetailed;
|
|
89
|
+
forward: URL;
|
|
90
|
+
}, server: ProxyServer<IncomingMessage | Http2ServerRequest, ServerResponse | Http2ServerResponse>, head?: Buffer, callback?: (err: any, req: IncomingMessage | Http2ServerRequest, socket: T, url?: any) => void) => void | true;
|
|
91
|
+
interface ProxyServerEventMap<Req extends http__default.IncomingMessage | http2.Http2ServerRequest = http__default.IncomingMessage, Res extends http__default.ServerResponse | http2.Http2ServerResponse = http__default.ServerResponse> {
|
|
92
|
+
error: [err: Error, req?: Req, res?: Res | net__default.Socket, target?: URL | ProxyTarget];
|
|
93
|
+
start: [req: Req, res: Res, target: URL | ProxyTarget];
|
|
94
|
+
econnreset: [err: Error, req: Req, res: Res, target: URL | ProxyTarget];
|
|
95
|
+
proxyReq: [proxyReq: http__default.ClientRequest, req: Req, res: Res, options: ProxyServerOptions];
|
|
96
|
+
proxyReqWs: [proxyReq: http__default.ClientRequest, req: Req, socket: net__default.Socket, options: ProxyServerOptions, head: any];
|
|
97
|
+
proxyRes: [proxyRes: http__default.IncomingMessage, req: Req, res: Res];
|
|
98
|
+
end: [req: Req, res: Res, proxyRes: http__default.IncomingMessage];
|
|
99
|
+
open: [proxySocket: net__default.Socket];
|
|
100
|
+
/** @deprecated */
|
|
101
|
+
proxySocket: [proxySocket: net__default.Socket];
|
|
102
|
+
close: [proxyRes: Req, proxySocket: net__default.Socket, proxyHead: any];
|
|
103
|
+
}
|
|
104
|
+
declare class ProxyServer<Req extends http__default.IncomingMessage | http2.Http2ServerRequest = http__default.IncomingMessage, Res extends http__default.ServerResponse | http2.Http2ServerResponse = http__default.ServerResponse> extends EventEmitter<ProxyServerEventMap<Req, Res>> {
|
|
105
|
+
private _server?;
|
|
106
|
+
_webPasses: ProxyMiddleware<http__default.ServerResponse>[];
|
|
107
|
+
_wsPasses: ProxyMiddleware<net__default.Socket>[];
|
|
108
|
+
options: ProxyServerOptions;
|
|
109
|
+
web: (req: Req, res: Res, opts?: ProxyServerOptions, head?: any) => Promise<void>;
|
|
110
|
+
ws: (req: Req, socket: net__default.Socket, opts: ProxyServerOptions, head?: any) => Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Creates the proxy server with specified options.
|
|
113
|
+
* @param options - Config object passed to the proxy
|
|
114
|
+
*/
|
|
115
|
+
constructor(options?: ProxyServerOptions);
|
|
116
|
+
/**
|
|
117
|
+
* A function that wraps the object in a webserver, for your convenience
|
|
118
|
+
* @param port - Port to listen on
|
|
119
|
+
* @param hostname - The hostname to listen on
|
|
120
|
+
* @param listeningListener - A callback function that is called when the server starts listening
|
|
121
|
+
*/
|
|
122
|
+
listen(port: number, hostname?: string, listeningListener?: () => void): this;
|
|
123
|
+
/**
|
|
124
|
+
* A function that closes the inner webserver and stops listening on given port
|
|
125
|
+
*/
|
|
126
|
+
close(callback?: () => void): void;
|
|
127
|
+
before<Type extends "ws" | "web">(type: Type, passName: string, pass: ProxyMiddleware<ResOfType<Type>>): void;
|
|
128
|
+
after<Type extends "ws" | "web">(type: Type, passName: string, pass: ProxyMiddleware<ResOfType<Type>>): void;
|
|
129
|
+
/** @internal */
|
|
130
|
+
_getPasses<Type extends "ws" | "web">(type: Type): ProxyMiddleware<ResOfType<Type>>[];
|
|
248
131
|
}
|
|
249
132
|
|
|
250
133
|
/**
|
|
@@ -253,27 +136,30 @@ declare namespace Server {
|
|
|
253
136
|
*/
|
|
254
137
|
|
|
255
138
|
type NextFunction<T = (err?: any) => void> = T;
|
|
256
|
-
interface RequestHandler<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction> {
|
|
139
|
+
interface RequestHandler<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse, TNext = NextFunction> {
|
|
257
140
|
(req: TReq, res: TRes, next?: TNext): Promise<void>;
|
|
258
|
-
upgrade: (req:
|
|
141
|
+
upgrade: (req: TReq, socket: net.Socket, head: Buffer) => void;
|
|
259
142
|
}
|
|
260
|
-
type Filter<TReq = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
|
|
261
|
-
interface Plugin<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
|
262
|
-
(proxyServer:
|
|
143
|
+
type Filter<TReq extends http.IncomingMessage = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
|
|
144
|
+
interface Plugin<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
|
|
145
|
+
(proxyServer: ProxyServer<TReq, TRes>, options: Options<TReq, TRes>): void;
|
|
263
146
|
}
|
|
264
|
-
interface OnProxyEvent<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
|
265
|
-
error?:
|
|
266
|
-
proxyReq?:
|
|
267
|
-
proxyReqWs?:
|
|
268
|
-
proxyRes?:
|
|
269
|
-
open?:
|
|
270
|
-
close?:
|
|
271
|
-
start?:
|
|
272
|
-
end?:
|
|
273
|
-
econnreset?:
|
|
147
|
+
interface OnProxyEvent<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
|
|
148
|
+
error?: (err: Error, req: TReq, res: TRes | net.Socket, target?: string | Partial<URL>) => void;
|
|
149
|
+
proxyReq?: (proxyReq: http.ClientRequest, req: TReq, res: TRes, options: ProxyServerOptions) => void;
|
|
150
|
+
proxyReqWs?: (proxyReq: http.ClientRequest, req: TReq, socket: net.Socket, options: ProxyServerOptions, head: any) => void;
|
|
151
|
+
proxyRes?: (proxyRes: TReq, req: TReq, res: TRes) => void | Promise<void>;
|
|
152
|
+
open?: (proxySocket: net.Socket) => void;
|
|
153
|
+
close?: (proxyRes: TReq, proxySocket: net.Socket, proxyHead: any) => void;
|
|
154
|
+
start?: (req: TReq, res: TRes, target: string | Partial<URL>) => void;
|
|
155
|
+
end?: (req: TReq, res: TRes, proxyRes: TReq) => void;
|
|
156
|
+
econnreset?: (err: Error, req: TReq, res: TRes, target: string | Partial<URL>) => void;
|
|
274
157
|
}
|
|
275
158
|
type Logger = Pick<Console, 'info' | 'warn' | 'error'>;
|
|
276
|
-
|
|
159
|
+
type PathRewriteConfig<TReq extends http.IncomingMessage = http.IncomingMessage> = {
|
|
160
|
+
[regexp: string]: string;
|
|
161
|
+
} | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise<string>);
|
|
162
|
+
interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> extends ProxyServerOptions {
|
|
277
163
|
/**
|
|
278
164
|
* Narrow down requests to proxy or not.
|
|
279
165
|
* Filter on {@link http.IncomingMessage.url `pathname`} which is relative to the proxy's "mounting" point in the server.
|
|
@@ -294,9 +180,7 @@ interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> exten
|
|
|
294
180
|
* ```
|
|
295
181
|
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
|
|
296
182
|
*/
|
|
297
|
-
pathRewrite?:
|
|
298
|
-
[regexp: string]: string;
|
|
299
|
-
} | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise<string>);
|
|
183
|
+
pathRewrite?: PathRewriteConfig<TReq>;
|
|
300
184
|
/**
|
|
301
185
|
* Access the internal http-proxy server instance to customize behavior
|
|
302
186
|
*
|
|
@@ -351,9 +235,7 @@ interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> exten
|
|
|
351
235
|
* ```
|
|
352
236
|
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md
|
|
353
237
|
*/
|
|
354
|
-
router?:
|
|
355
|
-
[hostOrPath: string]: Server.ServerOptions['target'];
|
|
356
|
-
} | ((req: TReq) => Server.ServerOptions['target']) | ((req: TReq) => Promise<Server.ServerOptions['target']>);
|
|
238
|
+
router?: Record<string, ProxyServerOptions['target']> | ((req: TReq) => ProxyServerOptions['target']) | ((req: TReq) => Promise<ProxyServerOptions['target']>);
|
|
357
239
|
/**
|
|
358
240
|
* Log information from http-proxy-middleware
|
|
359
241
|
* @example
|
|
@@ -365,12 +247,88 @@ interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> exten
|
|
|
365
247
|
* @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/logger.md
|
|
366
248
|
* @since v3.0.0
|
|
367
249
|
*/
|
|
368
|
-
logger?: Logger
|
|
250
|
+
logger?: Logger;
|
|
369
251
|
}
|
|
370
252
|
|
|
371
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Create proxy middleware for Express-like servers. ([list of servers with examples](https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md))
|
|
255
|
+
*
|
|
256
|
+
* @example Basic proxy to a single target.
|
|
257
|
+
* ```ts
|
|
258
|
+
* import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
259
|
+
*
|
|
260
|
+
* const proxy = createProxyMiddleware({
|
|
261
|
+
* target: 'http://www.example.org',
|
|
262
|
+
* changeOrigin: true,
|
|
263
|
+
* });
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @example Proxy only matching paths and rewrite the forwarded path.
|
|
267
|
+
* ```ts
|
|
268
|
+
* import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
269
|
+
*
|
|
270
|
+
* const proxy = createProxyMiddleware({
|
|
271
|
+
* target: 'http://localhost:3000',
|
|
272
|
+
* pathFilter: '/api',
|
|
273
|
+
* pathRewrite: {
|
|
274
|
+
* '^/api/': '/',
|
|
275
|
+
* },
|
|
276
|
+
* });
|
|
277
|
+
* ```
|
|
278
|
+
*
|
|
279
|
+
* @example Native path rewrite by mounting at a route (alternative to `pathRewrite`).
|
|
280
|
+
* ```ts
|
|
281
|
+
* import express from 'express';
|
|
282
|
+
* import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
283
|
+
*
|
|
284
|
+
* const app = express();
|
|
285
|
+
* app.use(
|
|
286
|
+
* '/users',
|
|
287
|
+
* createProxyMiddleware({
|
|
288
|
+
* target: 'http://jsonplaceholder.typicode.com/users',
|
|
289
|
+
* changeOrigin: true,
|
|
290
|
+
* }),
|
|
291
|
+
* );
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @example Use framework-specific request/response types (Express).
|
|
295
|
+
* ```ts
|
|
296
|
+
* import type { Request, Response } from 'express';
|
|
297
|
+
* import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
298
|
+
*
|
|
299
|
+
* const proxy = createProxyMiddleware<Request, Response>({
|
|
300
|
+
* target: 'http://www.example.org/api',
|
|
301
|
+
* changeOrigin: true,
|
|
302
|
+
* });
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @example Intercept and modify a proxied response body.
|
|
306
|
+
* ```ts
|
|
307
|
+
* import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
|
|
308
|
+
*
|
|
309
|
+
* const proxy = createProxyMiddleware({
|
|
310
|
+
* target: 'http://www.example.org',
|
|
311
|
+
* selfHandleResponse: true,
|
|
312
|
+
* on: {
|
|
313
|
+
* proxyRes: responseInterceptor(async (responseBuffer) => {
|
|
314
|
+
* const response = responseBuffer.toString('utf8');
|
|
315
|
+
* return response.replace('Hello', 'Goodbye');
|
|
316
|
+
* }),
|
|
317
|
+
* },
|
|
318
|
+
* });
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @see https://github.com/chimurai/http-proxy-middleware/
|
|
322
|
+
* @see https://github.com/chimurai/http-proxy-middleware/#basic-usage
|
|
323
|
+
* @see https://github.com/chimurai/http-proxy-middleware/#intercept-and-manipulate-responses
|
|
324
|
+
* @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md
|
|
325
|
+
* @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathFilter.md
|
|
326
|
+
* @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
|
|
327
|
+
* @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/response-interceptor.md
|
|
328
|
+
*/
|
|
329
|
+
declare function createProxyMiddleware<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse, TNext = NextFunction>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext>;
|
|
372
330
|
|
|
373
|
-
type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes:
|
|
331
|
+
type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: http.IncomingMessage, req: TReq, res: TRes) => Promise<Buffer | string>;
|
|
374
332
|
/**
|
|
375
333
|
* Intercept responses from upstream.
|
|
376
334
|
* Automatically decompress (deflate, gzip, brotli).
|
|
@@ -378,7 +336,7 @@ type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buf
|
|
|
378
336
|
*
|
|
379
337
|
* NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
|
|
380
338
|
*/
|
|
381
|
-
declare function responseInterceptor<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse>(interceptor: Interceptor<TReq, TRes>): (proxyRes:
|
|
339
|
+
declare function responseInterceptor<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse>(interceptor: Interceptor<TReq, TRes>): (proxyRes: http.IncomingMessage, req: TReq, res: TRes) => Promise<void>;
|
|
382
340
|
|
|
383
341
|
type BodyParserLikeRequest = http.IncomingMessage & {
|
|
384
342
|
body?: any;
|
|
@@ -420,125 +378,5 @@ declare const loggerPlugin: Plugin;
|
|
|
420
378
|
*/
|
|
421
379
|
declare const proxyEventsPlugin: Plugin;
|
|
422
380
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
*
|
|
426
|
-
* Will be removed in a future version.
|
|
427
|
-
*/
|
|
428
|
-
interface LegacyOptions<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends Options<TReq, TRes> {
|
|
429
|
-
/**
|
|
430
|
-
* @deprecated
|
|
431
|
-
* Use `on.error` instead.
|
|
432
|
-
*
|
|
433
|
-
* @example
|
|
434
|
-
* ```js
|
|
435
|
-
* {
|
|
436
|
-
* on: {
|
|
437
|
-
* error: () => {}
|
|
438
|
-
* }
|
|
439
|
-
* ```
|
|
440
|
-
*/
|
|
441
|
-
onError?: (...args: any[]) => void;
|
|
442
|
-
/**
|
|
443
|
-
* @deprecated
|
|
444
|
-
* Use `on.proxyRes` instead.
|
|
445
|
-
*
|
|
446
|
-
* @example
|
|
447
|
-
* ```js
|
|
448
|
-
* {
|
|
449
|
-
* on: {
|
|
450
|
-
* proxyRes: () => {}
|
|
451
|
-
* }
|
|
452
|
-
* ```
|
|
453
|
-
*/
|
|
454
|
-
onProxyRes?: (...args: any[]) => void;
|
|
455
|
-
/**
|
|
456
|
-
* @deprecated
|
|
457
|
-
* Use `on.proxyReq` instead.
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
* ```js
|
|
461
|
-
* {
|
|
462
|
-
* on: {
|
|
463
|
-
* proxyReq: () => {}
|
|
464
|
-
* }
|
|
465
|
-
* ```
|
|
466
|
-
*/
|
|
467
|
-
onProxyReq?: (...args: any[]) => void;
|
|
468
|
-
/**
|
|
469
|
-
* @deprecated
|
|
470
|
-
* Use `on.proxyReqWs` instead.
|
|
471
|
-
*
|
|
472
|
-
* @example
|
|
473
|
-
* ```js
|
|
474
|
-
* {
|
|
475
|
-
* on: {
|
|
476
|
-
* proxyReqWs: () => {}
|
|
477
|
-
* }
|
|
478
|
-
* ```
|
|
479
|
-
*/
|
|
480
|
-
onProxyReqWs?: (...args: any[]) => void;
|
|
481
|
-
/**
|
|
482
|
-
* @deprecated
|
|
483
|
-
* Use `on.open` instead.
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* ```js
|
|
487
|
-
* {
|
|
488
|
-
* on: {
|
|
489
|
-
* open: () => {}
|
|
490
|
-
* }
|
|
491
|
-
* ```
|
|
492
|
-
*/
|
|
493
|
-
onOpen?: (...args: any[]) => void;
|
|
494
|
-
/**
|
|
495
|
-
* @deprecated
|
|
496
|
-
* Use `on.close` instead.
|
|
497
|
-
*
|
|
498
|
-
* @example
|
|
499
|
-
* ```js
|
|
500
|
-
* {
|
|
501
|
-
* on: {
|
|
502
|
-
* close: () => {}
|
|
503
|
-
* }
|
|
504
|
-
* ```
|
|
505
|
-
*/
|
|
506
|
-
onClose?: (...args: any[]) => void;
|
|
507
|
-
/**
|
|
508
|
-
* @deprecated
|
|
509
|
-
* Use `logger` instead.
|
|
510
|
-
*
|
|
511
|
-
* @example
|
|
512
|
-
* ```js
|
|
513
|
-
* {
|
|
514
|
-
* logger: console
|
|
515
|
-
* }
|
|
516
|
-
* ```
|
|
517
|
-
*/
|
|
518
|
-
logProvider?: any;
|
|
519
|
-
/**
|
|
520
|
-
* @deprecated
|
|
521
|
-
* Use `logger` instead.
|
|
522
|
-
*
|
|
523
|
-
* @example
|
|
524
|
-
* ```js
|
|
525
|
-
* {
|
|
526
|
-
* logger: console
|
|
527
|
-
* }
|
|
528
|
-
* ```
|
|
529
|
-
*/
|
|
530
|
-
logLevel?: any;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* @deprecated
|
|
535
|
-
* This function is deprecated and will be removed in a future version.
|
|
536
|
-
*
|
|
537
|
-
* Use {@link createProxyMiddleware} instead.
|
|
538
|
-
*/
|
|
539
|
-
declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(shortHand: string): RequestHandler<TReq, TRes>;
|
|
540
|
-
declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(legacyOptions: LegacyOptions<TReq, TRes>): RequestHandler<TReq, TRes>;
|
|
541
|
-
declare function legacyCreateProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse>(legacyContext: Filter<TReq>, legacyOptions: LegacyOptions<TReq, TRes>): RequestHandler<TReq, TRes>;
|
|
542
|
-
|
|
543
|
-
export { createProxyMiddleware, debugProxyErrorsPlugin, errorResponsePlugin, fixRequestBody, legacyCreateProxyMiddleware, loggerPlugin, proxyEventsPlugin, responseInterceptor };
|
|
544
|
-
export type { Filter, LegacyOptions, Options, Plugin, RequestHandler };
|
|
381
|
+
export { createProxyMiddleware, debugProxyErrorsPlugin, errorResponsePlugin, fixRequestBody, loggerPlugin, proxyEventsPlugin, responseInterceptor };
|
|
382
|
+
export type { Filter, Options, Plugin, RequestHandler };
|