@rsbuild/core 2.0.0-rc.0 → 2.0.0-rc.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.
Files changed (58) hide show
  1. package/compiled/connect-next/package.json +1 -1
  2. package/compiled/css-loader/index.js +2 -2
  3. package/compiled/html-rspack-plugin/index.js +14 -14
  4. package/compiled/http-proxy-middleware/index.d.ts +180 -386
  5. package/compiled/http-proxy-middleware/package.json +1 -1
  6. package/compiled/postcss/index.js +1 -1
  7. package/compiled/postcss/lib/at-rule.d.ts +0 -1
  8. package/compiled/postcss/lib/comment.d.ts +0 -1
  9. package/compiled/postcss/lib/container.d.ts +1 -6
  10. package/compiled/postcss/lib/css-syntax-error.d.ts +0 -1
  11. package/compiled/postcss/lib/declaration.d.ts +0 -1
  12. package/compiled/postcss/lib/document.d.ts +0 -1
  13. package/compiled/postcss/lib/fromJSON.d.ts +1 -1
  14. package/compiled/postcss/lib/input.d.ts +0 -1
  15. package/compiled/postcss/lib/lazy-result.d.ts +3 -4
  16. package/compiled/postcss/lib/list.d.ts +1 -1
  17. package/compiled/postcss/lib/no-work-result.d.ts +0 -1
  18. package/compiled/postcss/lib/node.d.ts +0 -1
  19. package/compiled/postcss/lib/parse.d.ts +1 -1
  20. package/compiled/postcss/lib/postcss.d.ts +1 -3
  21. package/compiled/postcss/lib/previous-map.d.ts +0 -1
  22. package/compiled/postcss/lib/processor.d.ts +0 -1
  23. package/compiled/postcss/lib/result.d.ts +0 -1
  24. package/compiled/postcss/lib/root.d.ts +0 -1
  25. package/compiled/postcss/lib/rule.d.ts +12 -12
  26. package/compiled/postcss/lib/stringifier.d.ts +0 -1
  27. package/compiled/postcss/lib/stringify.d.ts +1 -1
  28. package/compiled/postcss/lib/warning.d.ts +0 -1
  29. package/compiled/postcss/license +1 -1
  30. package/compiled/postcss/package.json +1 -1
  31. package/compiled/postcss-loader/index.js +6 -6
  32. package/compiled/rspack-chain/package.json +1 -1
  33. package/compiled/rspack-chain/types/index.d.ts +38 -115
  34. package/dist/1~rslib-runtime.js +1 -1
  35. package/dist/{552.js → 753.js} +143 -196
  36. package/dist/client/hmr.js +23 -10
  37. package/dist/connect-next.js +636 -26
  38. package/dist/connect-next.js.LICENSE.txt +14 -1
  39. package/dist/http-proxy-middleware.js +1169 -1226
  40. package/dist/http-proxy-middleware.js.LICENSE.txt +0 -35
  41. package/dist/index.js +1 -1
  42. package/dist/launch-editor-middleware.js +6 -6
  43. package/dist/manifest-plugin.js +8 -8
  44. package/dist/memfs.js +16 -56
  45. package/dist/tinyglobby.js +279 -127
  46. package/dist/ws.js +2 -2
  47. package/dist-types/client/hmr.d.ts +1 -1
  48. package/dist-types/helpers/index.d.ts +1 -1
  49. package/dist-types/helpers/url.d.ts +1 -1
  50. package/dist-types/pluginHelper.d.ts +1 -8
  51. package/dist-types/server/devServer.d.ts +9 -7
  52. package/dist-types/server/socketServer.d.ts +16 -4
  53. package/dist-types/types/config.d.ts +9 -3
  54. package/dist-types/types/rspack.d.ts +1 -1
  55. package/package.json +11 -11
  56. package/dist/debug.js +0 -503
  57. package/dist-types/plugins/esm.d.ts +0 -2
  58. /package/dist/{552.js.LICENSE.txt → 753.js.LICENSE.txt} +0 -0
@@ -1,250 +1,141 @@
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
+ // @ts-ignore
9
+ import { HttpBindings } from '@hono/node-server';
10
+ // @ts-ignore
11
+ import { MiddlewareHandler } from 'hono';
7
12
 
13
+ //#region src/types.d.ts
8
14
  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;
15
+ host?: string;
16
+ port?: number | string;
17
+ protocol?: string;
18
+ hostname?: string;
19
+ socketPath?: string;
20
+ key?: string;
21
+ passphrase?: string;
22
+ pfx?: Buffer | string;
23
+ cert?: string;
24
+ ca?: string;
25
+ ciphers?: string;
26
+ secureProtocol?: string;
21
27
  }
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;
28
+ type ProxyTarget = string | URL | ProxyTargetDetailed;
29
+ interface ProxyServerOptions {
30
+ /** URL string to be parsed. */
31
+ target?: ProxyTarget;
32
+ /** URL string to be parsed. */
33
+ forward?: ProxyTarget;
34
+ /** Object to be passed to http(s).request. */
35
+ agent?: any;
36
+ /** Enable HTTP/2 listener, default is `false` */
37
+ http2?: boolean;
38
+ /** Object to be passed to https.createServer()
39
+ * or http2.createSecureServer() if the `http2` option is enabled
40
+ */
41
+ ssl?: any;
42
+ /** If you want to proxy websockets. */
43
+ ws?: boolean;
44
+ /** Adds x- forward headers. */
45
+ xfwd?: boolean;
46
+ /** Verify SSL certificate. */
47
+ secure?: boolean;
48
+ /** Explicitly specify if we are proxying to another proxy. */
49
+ toProxy?: boolean;
50
+ /** Specify whether you want to prepend the target's path to the proxy path. */
51
+ prependPath?: boolean;
52
+ /** Specify whether you want to ignore the proxy path of the incoming request. */
53
+ ignorePath?: boolean;
54
+ /** Local interface string to bind for outgoing connections. */
55
+ localAddress?: string;
56
+ /** Changes the origin of the host header to the target URL. */
57
+ changeOrigin?: boolean;
58
+ /** specify whether you want to keep letter case of response header key */
59
+ preserveHeaderKeyCase?: boolean;
60
+ /** Basic authentication i.e. 'user:password' to compute an Authorization header. */
61
+ auth?: string;
62
+ /** Rewrites the location hostname on (301 / 302 / 307 / 308) redirects, Default: null. */
63
+ hostRewrite?: string;
64
+ /** Rewrites the location host/ port on (301 / 302 / 307 / 308) redirects based on requested host/ port.Default: false. */
65
+ autoRewrite?: boolean;
66
+ /** Rewrites the location protocol on (301 / 302 / 307 / 308) redirects to 'http' or 'https'.Default: null. */
67
+ protocolRewrite?: string;
68
+ /** Rewrites domain of set-cookie headers. */
69
+ cookieDomainRewrite?: false | string | {
70
+ [oldDomain: string]: string;
71
+ };
72
+ /** Rewrites path of set-cookie headers. Default: false */
73
+ cookiePathRewrite?: false | string | {
74
+ [oldPath: string]: string;
75
+ };
76
+ /** Object with extra headers to be added to target requests. */
77
+ headers?: {
78
+ [header: string]: string;
79
+ };
80
+ /** Timeout (in milliseconds) when proxy receives no response from target. Default: 120000 (2 minutes) */
81
+ proxyTimeout?: number;
82
+ /** Timeout (in milliseconds) for incoming requests */
83
+ timeout?: number;
84
+ /** 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 */
85
+ selfHandleResponse?: boolean;
86
+ /** Follow HTTP redirects from target. `true` = max 5 hops; number = custom max. */
87
+ followRedirects?: boolean | number;
88
+ /** Buffer */
89
+ buffer?: stream.Stream;
137
90
  }
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;
91
+ //#endregion
92
+ //#region src/middleware/_utils.d.ts
93
+ type ResOfType<T extends "web" | "ws"> = T extends "ws" ? T extends "web" ? ServerResponse | Http2ServerResponse | Socket : Socket : T extends "web" ? ServerResponse | Http2ServerResponse : never;
94
+ type ProxyMiddleware<T extends ServerResponse | Http2ServerResponse | Socket> = (req: IncomingMessage | Http2ServerRequest, res: T, opts: ProxyServerOptions & {
95
+ target: URL | ProxyTargetDetailed;
96
+ forward: URL;
97
+ }, server: ProxyServer<IncomingMessage | Http2ServerRequest, ServerResponse | Http2ServerResponse>, head?: Buffer, callback?: (err: any, req: IncomingMessage | Http2ServerRequest, socket: T, url?: any) => void) => void | true;
98
+ //#endregion
99
+ //#region src/server.d.ts
100
+ interface ProxyServerEventMap<Req extends http__default.IncomingMessage | http2.Http2ServerRequest = http__default.IncomingMessage, Res extends http__default.ServerResponse | http2.Http2ServerResponse = http__default.ServerResponse> {
101
+ error: [err: Error, req?: Req, res?: Res | net__default.Socket, target?: URL | ProxyTarget];
102
+ start: [req: Req, res: Res, target: URL | ProxyTarget];
103
+ econnreset: [err: Error, req: Req, res: Res, target: URL | ProxyTarget];
104
+ proxyReq: [proxyReq: http__default.ClientRequest, req: Req, res: Res, options: ProxyServerOptions];
105
+ proxyReqWs: [proxyReq: http__default.ClientRequest, req: Req, socket: net__default.Socket, options: ProxyServerOptions, head: any];
106
+ proxyRes: [proxyRes: http__default.IncomingMessage, req: Req, res: Res];
107
+ end: [req: Req, res: Res, proxyRes: http__default.IncomingMessage];
108
+ open: [proxySocket: net__default.Socket];
109
+ /** @deprecated */
110
+ proxySocket: [proxySocket: net__default.Socket];
111
+ close: [proxyRes: Req, proxySocket: net__default.Socket, proxyHead: any];
112
+ }
113
+ 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>> {
114
+ private _server?;
115
+ _webPasses: ProxyMiddleware<http__default.ServerResponse>[];
116
+ _wsPasses: ProxyMiddleware<net__default.Socket>[];
117
+ options: ProxyServerOptions;
118
+ web: (req: Req, res: Res, opts?: ProxyServerOptions, head?: any) => Promise<void>;
119
+ ws: (req: Req, socket: net__default.Socket, opts: ProxyServerOptions, head?: any) => Promise<void>;
120
+ /**
121
+ * Creates the proxy server with specified options.
122
+ * @param options - Config object passed to the proxy
123
+ */
124
+ constructor(options?: ProxyServerOptions);
125
+ /**
126
+ * A function that wraps the object in a webserver, for your convenience
127
+ * @param port - Port to listen on
128
+ * @param hostname - The hostname to listen on
129
+ */
130
+ listen(port: number, hostname?: string): this;
131
+ /**
132
+ * A function that closes the inner webserver and stops listening on given port
133
+ */
134
+ close(callback?: () => void): void;
135
+ before<Type extends "ws" | "web">(type: Type, passName: string, pass: ProxyMiddleware<ResOfType<Type>>): void;
136
+ after<Type extends "ws" | "web">(type: Type, passName: string, pass: ProxyMiddleware<ResOfType<Type>>): void;
137
+ /** @internal */
138
+ _getPasses<Type extends "ws" | "web">(type: Type): ProxyMiddleware<ResOfType<Type>>[];
248
139
  }
249
140
 
250
141
  /**
@@ -253,27 +144,27 @@ declare namespace Server {
253
144
  */
254
145
 
255
146
  type NextFunction<T = (err?: any) => void> = T;
256
- interface RequestHandler<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction> {
147
+ interface RequestHandler<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse, TNext = NextFunction> {
257
148
  (req: TReq, res: TRes, next?: TNext): Promise<void>;
258
149
  upgrade: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
259
150
  }
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;
151
+ type Filter<TReq extends http.IncomingMessage = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
152
+ interface Plugin<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
153
+ (proxyServer: ProxyServer<TReq, TRes>, options: Options<TReq, TRes>): void;
263
154
  }
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>;
155
+ interface OnProxyEvent<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
156
+ error?: (err: Error, req: TReq, res: TRes | net.Socket, target?: string | Partial<URL>) => void;
157
+ proxyReq?: (proxyReq: http.ClientRequest, req: TReq, res: TRes, options: ProxyServerOptions) => void;
158
+ proxyReqWs?: (proxyReq: http.ClientRequest, req: TReq, socket: net.Socket, options: ProxyServerOptions, head: any) => void;
159
+ proxyRes?: (proxyRes: TReq, req: TReq, res: TRes) => void | Promise<void>;
160
+ open?: (proxySocket: net.Socket) => void;
161
+ close?: (proxyRes: TReq, proxySocket: net.Socket, proxyHead: any) => void;
162
+ start?: (req: TReq, res: TRes, target: string | Partial<URL>) => void;
163
+ end?: (req: TReq, res: TRes, proxyRes: TReq) => void;
164
+ econnreset?: (err: Error, req: TReq, res: TRes, target: string | Partial<URL>) => void;
274
165
  }
275
166
  type Logger = Pick<Console, 'info' | 'warn' | 'error'>;
276
- interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends Server.ServerOptions {
167
+ interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> extends ProxyServerOptions {
277
168
  /**
278
169
  * Narrow down requests to proxy or not.
279
170
  * Filter on {@link http.IncomingMessage.url `pathname`} which is relative to the proxy's "mounting" point in the server.
@@ -352,8 +243,8 @@ interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> exten
352
243
  * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md
353
244
  */
354
245
  router?: {
355
- [hostOrPath: string]: Server.ServerOptions['target'];
356
- } | ((req: TReq) => Server.ServerOptions['target']) | ((req: TReq) => Promise<Server.ServerOptions['target']>);
246
+ [hostOrPath: string]: ProxyServerOptions['target'];
247
+ } | ((req: TReq) => ProxyServerOptions['target']) | ((req: TReq) => Promise<ProxyServerOptions['target']>);
357
248
  /**
358
249
  * Log information from http-proxy-middleware
359
250
  * @example
@@ -365,12 +256,35 @@ interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> exten
365
256
  * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/logger.md
366
257
  * @since v3.0.0
367
258
  */
368
- logger?: Logger | any;
259
+ logger?: Logger;
369
260
  }
370
261
 
371
- declare function createProxyMiddleware<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction>(options: Options<TReq, TRes>): RequestHandler<TReq, TRes, TNext>;
262
+ 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
263
 
373
- type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: TReq, req: TReq, res: TRes) => Promise<Buffer | string>;
264
+ /**
265
+ * Creates a Hono middleware that proxies requests using http-proxy-middleware.
266
+ *
267
+ * `@remarks`
268
+ * This middleware requires Hono to be running on Node.js via `@hono/node-server`.
269
+ * It uses `c.env.incoming` and `c.env.outgoing` which are only available with `HttpBindings`.
270
+ *
271
+ * `@experimental` This API is experimental and may change without a major version bump.
272
+ *
273
+ * `@example`
274
+ * ```ts
275
+ * import { serve } from '@hono/node-server';
276
+ * import { Hono } from 'hono';
277
+ * import { createHonoProxyMiddleware } from 'http-proxy-middleware';
278
+ *
279
+ * const app = new Hono();
280
+ * app.use('/api', createHonoProxyMiddleware({ target: 'http://example.com', changeOrigin: true }));
281
+ * serve(app);
282
+ */
283
+ declare function createHonoProxyMiddleware(options: Options): MiddlewareHandler<{
284
+ Bindings: HttpBindings;
285
+ }>;
286
+
287
+ type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buffer: Buffer, proxyRes: http.IncomingMessage, req: TReq, res: TRes) => Promise<Buffer | string>;
374
288
  /**
375
289
  * Intercept responses from upstream.
376
290
  * Automatically decompress (deflate, gzip, brotli).
@@ -378,7 +292,7 @@ type Interceptor<TReq = http.IncomingMessage, TRes = http.ServerResponse> = (buf
378
292
  *
379
293
  * NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
380
294
  */
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>;
295
+ 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
296
 
383
297
  type BodyParserLikeRequest = http.IncomingMessage & {
384
298
  body?: any;
@@ -420,125 +334,5 @@ declare const loggerPlugin: Plugin;
420
334
  */
421
335
  declare const proxyEventsPlugin: Plugin;
422
336
 
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 };
337
+ export { createHonoProxyMiddleware, createProxyMiddleware, debugProxyErrorsPlugin, errorResponsePlugin, fixRequestBody, loggerPlugin, proxyEventsPlugin, responseInterceptor };
338
+ 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.3","license":"MIT","types":"index.d.ts","type":"module"}