@rspack-debug/core 2.0.0 → 2.0.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.
@@ -1,250 +1,135 @@
1
- /// <reference types="node" />
2
- import * as http from 'http';
3
- import events from 'events';
4
- import * as net from 'net';
5
- import stream from 'stream';
6
- import * as url from 'url';
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';
8
+ import { HttpBindings } from '@hono/node-server';
9
+ import { MiddlewareHandler } from 'hono';
7
10
 
8
11
  interface ProxyTargetDetailed {
9
- host: string;
10
- port: number;
11
- protocol?: string | undefined;
12
- hostname?: string | undefined;
13
- socketPath?: string | undefined;
14
- key?: string | undefined;
15
- passphrase?: string | undefined;
16
- pfx?: Buffer | string | undefined;
17
- cert?: string | undefined;
18
- ca?: string | undefined;
19
- ciphers?: string | undefined;
20
- secureProtocol?: string | undefined;
12
+ host?: string;
13
+ port?: number | string;
14
+ protocol?: string;
15
+ hostname?: string;
16
+ socketPath?: string;
17
+ key?: string;
18
+ passphrase?: string;
19
+ pfx?: Buffer | string;
20
+ cert?: string;
21
+ ca?: string;
22
+ ciphers?: string;
23
+ secureProtocol?: string;
21
24
  }
22
-
23
- declare class Server<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse>
24
- extends events.EventEmitter
25
- {
26
- /**
27
- * Creates the proxy server with specified options.
28
- * @param options - Config object passed to the proxy
29
- */
30
- constructor(options?: Server.ServerOptions);
31
-
32
- /**
33
- * Used for proxying regular HTTP(S) requests
34
- * @param req - Client request.
35
- * @param res - Client response.
36
- * @param options - Additional options.
37
- */
38
- web(
39
- req: http.IncomingMessage,
40
- res: http.ServerResponse,
41
- options?: Server.ServerOptions,
42
- callback?: Server.ErrorCallback,
43
- ): void;
44
-
45
- /**
46
- * Used for proxying WS(S) requests
47
- * @param req - Client request.
48
- * @param socket - Client socket.
49
- * @param head - Client head.
50
- * @param options - Additionnal options.
51
- */
52
- ws(
53
- req: http.IncomingMessage,
54
- socket: any,
55
- head: any,
56
- options?: Server.ServerOptions,
57
- callback?: Server.ErrorCallback,
58
- ): void;
59
-
60
- /**
61
- * A function that wraps the object in a webserver, for your convenience
62
- * @param port - Port to listen on
63
- * @param hostname - The hostname to listen on
64
- */
65
- listen(port: number, hostname?: string): Server<TIncomingMessage, TServerResponse>;
66
-
67
- /**
68
- * A function that closes the inner webserver and stops listening on given port
69
- */
70
- close(callback?: () => void): void;
71
-
72
- /**
73
- * Creates the proxy server with specified options.
74
- * @param options Config object passed to the proxy
75
- * @returns Proxy object with handlers for `ws` and `web` requests
76
- */
77
- // tslint:disable:no-unnecessary-generics
78
- static createProxyServer<TIncomingMessage = http.IncomingMessage, TServerResponse = http.ServerResponse>(
79
- options?: Server.ServerOptions,
80
- ): Server<TIncomingMessage, TServerResponse>;
81
-
82
- /**
83
- * Creates the proxy server with specified options.
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;
25
+ type ProxyTarget = string | URL | ProxyTargetDetailed;
26
+ interface ProxyServerOptions {
27
+ /** URL string to be parsed. */
28
+ target?: ProxyTarget;
29
+ /** URL string to be parsed. */
30
+ forward?: ProxyTarget;
31
+ /** Object to be passed to http(s).request. */
32
+ agent?: any;
33
+ /** Enable HTTP/2 listener, default is `false` */
34
+ http2?: boolean;
35
+ /** Object to be passed to https.createServer()
36
+ * or http2.createSecureServer() if the `http2` option is enabled
37
+ */
38
+ ssl?: any;
39
+ /** If you want to proxy websockets. */
40
+ ws?: boolean;
41
+ /** Adds x- forward headers. */
42
+ xfwd?: boolean;
43
+ /** Verify SSL certificate. */
44
+ secure?: boolean;
45
+ /** Explicitly specify if we are proxying to another proxy. */
46
+ toProxy?: boolean;
47
+ /** Specify whether you want to prepend the target's path to the proxy path. */
48
+ prependPath?: boolean;
49
+ /** Specify whether you want to ignore the proxy path of the incoming request. */
50
+ ignorePath?: boolean;
51
+ /** Local interface string to bind for outgoing connections. */
52
+ localAddress?: string;
53
+ /** Changes the origin of the host header to the target URL. */
54
+ changeOrigin?: boolean;
55
+ /** specify whether you want to keep letter case of response header key */
56
+ preserveHeaderKeyCase?: boolean;
57
+ /** Basic authentication i.e. 'user:password' to compute an Authorization header. */
58
+ auth?: string;
59
+ /** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
60
+ hostRewrite?: string;
61
+ /** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
62
+ autoRewrite?: boolean;
63
+ /** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
64
+ protocolRewrite?: string;
65
+ /** Rewrites domain of set-cookie headers. */
66
+ cookieDomainRewrite?: false | string | {
67
+ [oldDomain: string]: string;
68
+ };
69
+ /** Rewrites path of set-cookie headers. Default: false */
70
+ cookiePathRewrite?: false | string | {
71
+ [oldPath: string]: string;
72
+ };
73
+ /** Object with extra headers to be added to target requests. */
74
+ headers?: {
75
+ [header: string]: string;
76
+ };
77
+ /** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
78
+ proxyTimeout?: number;
79
+ /** Timeout (in milliseconds) for incoming requests */
80
+ timeout?: number;
81
+ /** 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 */
82
+ selfHandleResponse?: boolean;
83
+ /** Follow HTTP redirects from target. `true` = max 5 hops; number = custom max. */
84
+ followRedirects?: boolean | number;
85
+ /** Buffer */
86
+ buffer?: stream.Stream;
137
87
  }
138
-
139
- declare namespace Server {
140
- type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed;
141
- type ProxyTargetUrl = string | Partial<url.Url>;
142
-
143
- interface ServerOptions {
144
- /** URL string to be parsed with the url module. */
145
- target?: ProxyTarget | undefined;
146
- /** URL string to be parsed with the url module. */
147
- forward?: ProxyTargetUrl | undefined;
148
- /** Object to be passed to http(s).request. */
149
- agent?: any;
150
- /** Object to be passed to https.createServer(). */
151
- ssl?: any;
152
- /** If you want to proxy websockets. */
153
- ws?: boolean | undefined;
154
- /** Adds x- forward headers. */
155
- xfwd?: boolean | undefined;
156
- /** Verify SSL certificate. */
157
- secure?: boolean | undefined;
158
- /** Explicitly specify if we are proxying to another proxy. */
159
- toProxy?: boolean | undefined;
160
- /** Specify whether you want to prepend the target's path to the proxy path. */
161
- prependPath?: boolean | undefined;
162
- /** Specify whether you want to ignore the proxy path of the incoming request. */
163
- ignorePath?: boolean | undefined;
164
- /** Local interface string to bind for outgoing connections. */
165
- localAddress?: string | undefined;
166
- /** Changes the origin of the host header to the target URL. */
167
- changeOrigin?: boolean | undefined;
168
- /** specify whether you want to keep letter case of response header key */
169
- preserveHeaderKeyCase?: boolean | undefined;
170
- /** Basic authentication i.e. 'user:password' to compute an Authorization header. */
171
- auth?: string | undefined;
172
- /** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
173
- hostRewrite?: string | undefined;
174
- /** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
175
- autoRewrite?: boolean | undefined;
176
- /** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
177
- protocolRewrite?: string | undefined;
178
- /** rewrites domain of set-cookie headers. */
179
- cookieDomainRewrite?: false | string | { [oldDomain: string]: string } | undefined;
180
- /** rewrites path of set-cookie headers. Default: false */
181
- cookiePathRewrite?: false | string | { [oldPath: string]: string } | undefined;
182
- /** object with extra headers to be added to target requests. */
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;
88
+ type ResOfType<T extends "web" | "ws"> = T extends "ws" ? T extends "web" ? ServerResponse | Http2ServerResponse | Socket : Socket : T extends "web" ? ServerResponse | Http2ServerResponse : never;
89
+ type ProxyMiddleware<T extends ServerResponse | Http2ServerResponse | Socket> = (req: IncomingMessage | Http2ServerRequest, res: T, opts: ProxyServerOptions & {
90
+ target: URL | ProxyTargetDetailed;
91
+ forward: URL;
92
+ }, server: ProxyServer<IncomingMessage | Http2ServerRequest, ServerResponse | Http2ServerResponse>, head?: Buffer, callback?: (err: any, req: IncomingMessage | Http2ServerRequest, socket: T, url?: any) => void) => void | true;
93
+ interface ProxyServerEventMap<Req extends http__default.IncomingMessage | http2.Http2ServerRequest = http__default.IncomingMessage, Res extends http__default.ServerResponse | http2.Http2ServerResponse = http__default.ServerResponse> {
94
+ error: [err: Error, req?: Req, res?: Res | net__default.Socket, target?: URL | ProxyTarget];
95
+ start: [req: Req, res: Res, target: URL | ProxyTarget];
96
+ econnreset: [err: Error, req: Req, res: Res, target: URL | ProxyTarget];
97
+ proxyReq: [proxyReq: http__default.ClientRequest, req: Req, res: Res, options: ProxyServerOptions];
98
+ proxyReqWs: [proxyReq: http__default.ClientRequest, req: Req, socket: net__default.Socket, options: ProxyServerOptions, head: any];
99
+ proxyRes: [proxyRes: http__default.IncomingMessage, req: Req, res: Res];
100
+ end: [req: Req, res: Res, proxyRes: http__default.IncomingMessage];
101
+ open: [proxySocket: net__default.Socket];
102
+ /** @deprecated */
103
+ proxySocket: [proxySocket: net__default.Socket];
104
+ close: [proxyRes: Req, proxySocket: net__default.Socket, proxyHead: any];
105
+ }
106
+ 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>> {
107
+ private _server?;
108
+ _webPasses: ProxyMiddleware<http__default.ServerResponse>[];
109
+ _wsPasses: ProxyMiddleware<net__default.Socket>[];
110
+ options: ProxyServerOptions;
111
+ web: (req: Req, res: Res, opts?: ProxyServerOptions, head?: any) => Promise<void>;
112
+ ws: (req: Req, socket: net__default.Socket, opts: ProxyServerOptions, head?: any) => Promise<void>;
113
+ /**
114
+ * Creates the proxy server with specified options.
115
+ * @param options - Config object passed to the proxy
116
+ */
117
+ constructor(options?: ProxyServerOptions);
118
+ /**
119
+ * A function that wraps the object in a webserver, for your convenience
120
+ * @param port - Port to listen on
121
+ * @param hostname - The hostname to listen on
122
+ * @param listeningListener - A callback function that is called when the server starts listening
123
+ */
124
+ listen(port: number, hostname?: string, listeningListener?: () => void): this;
125
+ /**
126
+ * A function that closes the inner webserver and stops listening on given port
127
+ */
128
+ close(callback?: () => void): void;
129
+ before<Type extends "ws" | "web">(type: Type, passName: string, pass: ProxyMiddleware<ResOfType<Type>>): void;
130
+ after<Type extends "ws" | "web">(type: Type, passName: string, pass: ProxyMiddleware<ResOfType<Type>>): void;
131
+ /** @internal */
132
+ _getPasses<Type extends "ws" | "web">(type: Type): ProxyMiddleware<ResOfType<Type>>[];
248
133
  }
249
134
 
250
135
  /**
@@ -253,27 +138,30 @@ declare namespace Server {
253
138
  */
254
139
 
255
140
  type NextFunction<T = (err?: any) => void> = T;
256
- interface RequestHandler<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction> {
141
+ interface RequestHandler<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse, TNext = NextFunction> {
257
142
  (req: TReq, res: TRes, next?: TNext): Promise<void>;
258
- upgrade: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
143
+ upgrade: (req: TReq, socket: net.Socket, head: Buffer) => void;
259
144
  }
260
- type Filter<TReq = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
261
- interface Plugin<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
262
- (proxyServer: Server<TReq, TRes>, options: Options<TReq, TRes>): void;
145
+ type Filter<TReq extends http.IncomingMessage = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
146
+ interface Plugin<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
147
+ (proxyServer: ProxyServer<TReq, TRes>, options: Options<TReq, TRes>): void;
263
148
  }
264
- interface OnProxyEvent<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
265
- error?: Server.ErrorCallback<Error, TReq, TRes>;
266
- proxyReq?: Server.ProxyReqCallback<http.ClientRequest, TReq, TRes>;
267
- proxyReqWs?: Server.ProxyReqWsCallback<http.ClientRequest, TReq>;
268
- proxyRes?: Server.ProxyResCallback<TReq, TRes>;
269
- open?: Server.OpenCallback;
270
- close?: Server.CloseCallback<TReq>;
271
- start?: Server.StartCallback<TReq, TRes>;
272
- end?: Server.EndCallback<TReq, TRes>;
273
- econnreset?: Server.EconnresetCallback<Error, TReq, TRes>;
149
+ interface OnProxyEvent<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
150
+ error?: (err: Error, req: TReq, res: TRes | net.Socket, target?: string | Partial<URL>) => void;
151
+ proxyReq?: (proxyReq: http.ClientRequest, req: TReq, res: TRes, options: ProxyServerOptions) => void;
152
+ proxyReqWs?: (proxyReq: http.ClientRequest, req: TReq, socket: net.Socket, options: ProxyServerOptions, head: any) => void;
153
+ proxyRes?: (proxyRes: TReq, req: TReq, res: TRes) => void | Promise<void>;
154
+ open?: (proxySocket: net.Socket) => void;
155
+ close?: (proxyRes: TReq, proxySocket: net.Socket, proxyHead: any) => void;
156
+ start?: (req: TReq, res: TRes, target: string | Partial<URL>) => void;
157
+ end?: (req: TReq, res: TRes, proxyRes: TReq) => void;
158
+ econnreset?: (err: Error, req: TReq, res: TRes, target: string | Partial<URL>) => void;
274
159
  }
275
160
  type Logger = Pick<Console, 'info' | 'warn' | 'error'>;
276
- interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends Server.ServerOptions {
161
+ type PathRewriteConfig<TReq extends http.IncomingMessage = http.IncomingMessage> = {
162
+ [regexp: string]: string;
163
+ } | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise<string>);
164
+ interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> extends ProxyServerOptions {
277
165
  /**
278
166
  * Narrow down requests to proxy or not.
279
167
  * Filter on {@link http.IncomingMessage.url `pathname`} which is relative to the proxy's "mounting" point in the server.
@@ -294,9 +182,7 @@ interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> exten
294
182
  * ```
295
183
  * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
296
184
  */
297
- pathRewrite?: {
298
- [regexp: string]: string;
299
- } | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise<string>);
185
+ pathRewrite?: PathRewriteConfig<TReq>;
300
186
  /**
301
187
  * Access the internal http-proxy server instance to customize behavior
302
188
  *
@@ -351,9 +237,7 @@ interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> exten
351
237
  * ```
352
238
  * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md
353
239
  */
354
- router?: {
355
- [hostOrPath: string]: Server.ServerOptions['target'];
356
- } | ((req: TReq) => Server.ServerOptions['target']) | ((req: TReq) => Promise<Server.ServerOptions['target']>);
240
+ router?: Record<string, ProxyServerOptions['target']> | ((req: TReq) => ProxyServerOptions['target']) | ((req: TReq) => Promise<ProxyServerOptions['target']>);
357
241
  /**
358
242
  * Log information from http-proxy-middleware
359
243
  * @example
@@ -365,12 +249,111 @@ interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> exten
365
249
  * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/logger.md
366
250
  * @since v3.0.0
367
251
  */
368
- logger?: Logger | any;
252
+ logger?: Logger;
369
253
  }
370
254
 
371
- declare function createProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext>;
255
+ /**
256
+ * Create proxy middleware for Express-like servers. ([list of servers with examples](https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md))
257
+ *
258
+ * @example Basic proxy to a single target.
259
+ * ```ts
260
+ * import { createProxyMiddleware } from 'http-proxy-middleware';
261
+ *
262
+ * const proxy = createProxyMiddleware({
263
+ * target: 'http://www.example.org',
264
+ * changeOrigin: true,
265
+ * });
266
+ * ```
267
+ *
268
+ * @example Proxy only matching paths and rewrite the forwarded path.
269
+ * ```ts
270
+ * import { createProxyMiddleware } from 'http-proxy-middleware';
271
+ *
272
+ * const proxy = createProxyMiddleware({
273
+ * target: 'http://localhost:3000',
274
+ * pathFilter: '/api',
275
+ * pathRewrite: {
276
+ * '^/api/': '/',
277
+ * },
278
+ * });
279
+ * ```
280
+ *
281
+ * @example Native path rewrite by mounting at a route (alternative to `pathRewrite`).
282
+ * ```ts
283
+ * import express from 'express';
284
+ * import { createProxyMiddleware } from 'http-proxy-middleware';
285
+ *
286
+ * const app = express();
287
+ * app.use(
288
+ * '/users',
289
+ * createProxyMiddleware({
290
+ * target: 'http://jsonplaceholder.typicode.com/users',
291
+ * changeOrigin: true,
292
+ * }),
293
+ * );
294
+ * ```
295
+ *
296
+ * @example Use framework-specific request/response types (Express).
297
+ * ```ts
298
+ * import type { Request, Response } from 'express';
299
+ * import { createProxyMiddleware } from 'http-proxy-middleware';
300
+ *
301
+ * const proxy = createProxyMiddleware<Request, Response>({
302
+ * target: 'http://www.example.org/api',
303
+ * changeOrigin: true,
304
+ * });
305
+ * ```
306
+ *
307
+ * @example Intercept and modify a proxied response body.
308
+ * ```ts
309
+ * import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
310
+ *
311
+ * const proxy = createProxyMiddleware({
312
+ * target: 'http://www.example.org',
313
+ * selfHandleResponse: true,
314
+ * on: {
315
+ * proxyRes: responseInterceptor(async (responseBuffer) => {
316
+ * const response = responseBuffer.toString('utf8');
317
+ * return response.replace('Hello', 'Goodbye');
318
+ * }),
319
+ * },
320
+ * });
321
+ * ```
322
+ *
323
+ * @see https://github.com/chimurai/http-proxy-middleware/
324
+ * @see https://github.com/chimurai/http-proxy-middleware/#basic-usage
325
+ * @see https://github.com/chimurai/http-proxy-middleware/#intercept-and-manipulate-responses
326
+ * @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md
327
+ * @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathFilter.md
328
+ * @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
329
+ * @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/response-interceptor.md
330
+ */
331
+ 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>;
332
+
333
+ /**
334
+ * Creates a Hono middleware that proxies requests using http-proxy-middleware.
335
+ *
336
+ * `@remarks`
337
+ * This middleware requires Hono to be running on Node.js via `@hono/node-server`.
338
+ * It uses `c.env.incoming` and `c.env.outgoing` which are only available with `HttpBindings`.
339
+ *
340
+ * `@experimental` This API is experimental and may change without a major version bump.
341
+ *
342
+ * `@example`
343
+ * ```ts
344
+ * import { serve } from '@hono/node-server';
345
+ * import { Hono } from 'hono';
346
+ * import { createHonoProxyMiddleware } from 'http-proxy-middleware';
347
+ *
348
+ * const app = new Hono();
349
+ * app.use('/api', createHonoProxyMiddleware({ target: 'http://example.com', changeOrigin: true }));
350
+ * serve(app);
351
+ */
352
+ declare function createHonoProxyMiddleware(options: Options): MiddlewareHandler<{
353
+ Bindings: HttpBindings;
354
+ }>;
372
355
 
373
- type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: TReq, req: TReq, res: TRes) => Promise<Buffer | string>;
356
+ type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: http.IncomingMessage, req: TReq, res: TRes) => Promise<Buffer | string>;
374
357
  /**
375
358
  * Intercept responses from upstream.
376
359
  * Automatically decompress (deflate, gzip, brotli).
@@ -378,7 +361,7 @@ type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buf
378
361
  *
379
362
  * NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
380
363
  */
381
- 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>;
364
+ 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
365
 
383
366
  type BodyParserLikeRequest = http.IncomingMessage & {
384
367
  body?: any;
@@ -420,125 +403,5 @@ declare const loggerPlugin: Plugin;
420
403
  */
421
404
  declare const proxyEventsPlugin: Plugin;
422
405
 
423
- /**
424
- * @deprecated
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 };
406
+ export { createHonoProxyMiddleware, createProxyMiddleware, debugProxyErrorsPlugin, errorResponsePlugin, fixRequestBody, loggerPlugin, proxyEventsPlugin, responseInterceptor };
407
+ export type { Filter, Options, Plugin, RequestHandler };
@@ -1 +1 @@
1
- {"name":"http-proxy-middleware","author":"Steven Chim","version":"3.0.5","license":"MIT","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"http-proxy-middleware","author":"Steven Chim","version":"4.0.0-beta.5","license":"MIT","types":"index.d.ts","type":"module"}
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ __webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
34
34
  value: !0
35
35
  });
36
36
  }, __webpack_require__.add({
37
- "../../node_modules/.pnpm/enhanced-resolve@5.20.1/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js" (module, __unused_rspack_exports, __webpack_require__) {
37
+ "../../node_modules/.pnpm/enhanced-resolve@5.21.0/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js" (module, __unused_rspack_exports, __webpack_require__) {
38
38
  let { nextTick } = __webpack_require__("process"), dirname = (path)=>{
39
39
  let idx = path.length - 1;
40
40
  for(; idx >= 0;){
@@ -76,7 +76,7 @@ __webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
76
76
  constructor(duration, provider, syncProvider, providerContext){
77
77
  this._duration = duration, this._provider = provider, this._syncProvider = syncProvider, this._providerContext = providerContext, this._activeAsyncOperations = new Map(), this._data = new Map(), this._levels = [];
78
78
  for(let i = 0; i < 10; i++)this._levels.push(new Set());
79
- for(let i = 5000; i < duration; i += 500)this._levels.push(new Set());
79
+ if (duration !== 1 / 0) for(let i = 5000; i < duration; i += 500)this._levels.push(new Set());
80
80
  this._currentLevel = 0, this._tickInterval = Math.floor(duration / this._levels.length), this._mode = 0, this._timeout = void 0, this._nextDecay = void 0, this.provide = provider ? this.provide.bind(this) : null, this.provideSync = syncProvider ? this.provideSync.bind(this) : null;
81
81
  }
82
82
  provide(path, options, callback) {
@@ -176,7 +176,7 @@ __webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
176
176
  if (this._runDecays(), 0 === this._mode) return;
177
177
  timeout = Math.max(0, this._nextDecay - Date.now());
178
178
  }
179
- this._mode = 2;
179
+ if (this._mode = 2, this._duration === 1 / 0) return;
180
180
  let ref = setTimeout(()=>{
181
181
  this._mode = 1, this._runDecays();
182
182
  }, timeout);
@@ -1809,7 +1809,7 @@ function createDiagnosticArray(adm) {
1809
1809
  return copy.sort(compareFn), adm.spliceWithArray(0, adm.length, copy), this;
1810
1810
  },
1811
1811
  at: (index)=>adm.get(index),
1812
- concat: (...items)=>([].includes, adm.values().concat(...items)),
1812
+ concat: (...items)=>adm.values().concat(...items),
1813
1813
  flat: ()=>adm.values(),
1814
1814
  every: (predicate, thisArg)=>adm.values().every(predicate, thisArg),
1815
1815
  filter: (predicate, thisArg)=>adm.values().filter(predicate, thisArg),
@@ -6865,7 +6865,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
6865
6865
  return output.wasmLoading && enabledWasmLoadingTypes.add(output.wasmLoading), output.workerWasmLoading && enabledWasmLoadingTypes.add(output.workerWasmLoading), forEachEntry((desc)=>{
6866
6866
  desc.wasmLoading && enabledWasmLoadingTypes.add(desc.wasmLoading);
6867
6867
  }), Array.from(enabledWasmLoadingTypes);
6868
- }), D(output, 'bundlerInfo', {}), 'object' == typeof output.bundlerInfo && (D(output.bundlerInfo, 'version', "2.0.0"), D(output.bundlerInfo, 'bundler', 'rspack'), D(output.bundlerInfo, 'force', !1));
6868
+ }), D(output, 'bundlerInfo', {}), 'object' == typeof output.bundlerInfo && (D(output.bundlerInfo, 'version', "2.0.1"), D(output.bundlerInfo, 'bundler', 'rspack'), D(output.bundlerInfo, 'force', !1));
6869
6869
  }, applyExternalsPresetsDefaults = (externalsPresets, { targetProperties, buildHttp, outputModule })=>{
6870
6870
  let isUniversal = (key)=>!!(outputModule && targetProperties && null === targetProperties[key]);
6871
6871
  D(externalsPresets, 'web', !buildHttp && targetProperties && (targetProperties.web || isUniversal('node'))), D(externalsPresets, 'node', targetProperties && (targetProperties.node || isUniversal('node'))), D(externalsPresets, 'electron', targetProperties && targetProperties.electron || isUniversal('electron')), D(externalsPresets, 'electronMain', targetProperties && !!targetProperties.electron && (targetProperties.electronMain || isUniversal('electronMain'))), D(externalsPresets, 'electronPreload', targetProperties && !!targetProperties.electron && (targetProperties.electronPreload || isUniversal('electronPreload'))), D(externalsPresets, 'electronRenderer', targetProperties && !!targetProperties.electron && (targetProperties.electronRenderer || isUniversal('electronRenderer'))), D(externalsPresets, 'nwjs', targetProperties && (targetProperties.nwjs || isUniversal('nwjs')));
@@ -8119,7 +8119,7 @@ class MultiStats {
8119
8119
  obj.children = this.stats.map((stat, idx)=>{
8120
8120
  let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
8121
8121
  return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
8122
- }), childOptions.version && (obj.rspackVersion = "2.0.0", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
8122
+ }), childOptions.version && (obj.rspackVersion = "2.0.1", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
8123
8123
  let mapError = (j, obj)=>({
8124
8124
  ...obj,
8125
8125
  compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
@@ -8628,7 +8628,7 @@ let arraySum = (array)=>{
8628
8628
  let str = `${a}`, length = lengths[i];
8629
8629
  return str.length === length ? str : length > 5 ? `...${str.slice(-length + 3)}` : length > 0 ? str.slice(-length) : '';
8630
8630
  });
8631
- }, CachedInputFileSystem = __webpack_require__("../../node_modules/.pnpm/enhanced-resolve@5.20.1/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js");
8631
+ }, CachedInputFileSystem = __webpack_require__("../../node_modules/.pnpm/enhanced-resolve@5.21.0/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js");
8632
8632
  var CachedInputFileSystem_default = __webpack_require__.n(CachedInputFileSystem);
8633
8633
  class NodeEnvironmentPlugin {
8634
8634
  options;
@@ -9390,7 +9390,7 @@ let iterateConfig = (config, options, fn)=>{
9390
9390
  object.hash = context.getStatsCompilation(compilation).hash;
9391
9391
  },
9392
9392
  version: (object)=>{
9393
- object.version = "5.75.0", object.rspackVersion = "2.0.0";
9393
+ object.version = "5.75.0", object.rspackVersion = "2.0.1";
9394
9394
  },
9395
9395
  env: (object, _compilation, _context, { _env })=>{
9396
9396
  object.env = _env;
@@ -11048,7 +11048,7 @@ class TraceHookPlugin {
11048
11048
  });
11049
11049
  }
11050
11050
  }
11051
- let CORE_VERSION = "2.0.0", VFILES_BY_COMPILER = new WeakMap();
11051
+ let CORE_VERSION = "2.0.1", VFILES_BY_COMPILER = new WeakMap();
11052
11052
  class VirtualModulesPlugin {
11053
11053
  #staticModules;
11054
11054
  #compiler;
@@ -13351,7 +13351,7 @@ async function transform(source, options) {
13351
13351
  let _options = JSON.stringify(options || {});
13352
13352
  return binding_default().transform(source, _options);
13353
13353
  }
13354
- let exports_rspackVersion = "2.0.0", exports_version = "5.75.0", exports_WebpackError = Error, exports_config = {
13354
+ let exports_rspackVersion = "2.0.1", exports_version = "5.75.0", exports_WebpackError = Error, exports_config = {
13355
13355
  getNormalizedRspackOptions: getNormalizedRspackOptions,
13356
13356
  applyRspackOptionsDefaults: applyRspackOptionsDefaults,
13357
13357
  getNormalizedWebpackOptions: getNormalizedRspackOptions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-debug/core",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "Fast Rust-based bundler for the web with a modernized webpack API",
@@ -40,7 +40,7 @@
40
40
  "@ast-grep/napi": "^0.42.1",
41
41
  "@napi-rs/wasm-runtime": "1.1.4",
42
42
  "@rsbuild/plugin-node-polyfill": "^1.4.4",
43
- "@rslib/core": "0.21.2",
43
+ "@rslib/core": "0.21.3",
44
44
  "@rspack/lite-tapable": "1.1.0",
45
45
  "@swc/types": "0.1.26",
46
46
  "@types/node": "^20.19.39",
@@ -48,8 +48,8 @@
48
48
  "browserslist-load-config": "^1.0.1",
49
49
  "browserslist-to-es-version": "^1.4.1",
50
50
  "connect-next": "^4.0.1",
51
- "enhanced-resolve": "5.20.1",
52
- "http-proxy-middleware": "^3.0.5",
51
+ "enhanced-resolve": "5.21.0",
52
+ "http-proxy-middleware": "^4.0.0-beta.5",
53
53
  "memfs": "4.53.0",
54
54
  "open": "^11.0.0",
55
55
  "prebundle": "^1.6.4",
@@ -59,7 +59,7 @@
59
59
  "webpack-sources": "3.3.4"
60
60
  },
61
61
  "dependencies": {
62
- "@rspack/binding": "npm:@rspack-debug/binding@2.0.0"
62
+ "@rspack/binding": "npm:@rspack-debug/binding@2.0.1"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@module-federation/runtime-tools": "^0.24.1 || ^2.0.0",