@rsbuild/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.
@@ -10,7 +10,6 @@ import { HttpBindings } from '@hono/node-server';
10
10
  // @ts-ignore
11
11
  import { MiddlewareHandler } from 'hono';
12
12
 
13
- //#region src/types.d.ts
14
13
  interface ProxyTargetDetailed {
15
14
  host?: string;
16
15
  port?: number | string;
@@ -88,15 +87,11 @@ interface ProxyServerOptions {
88
87
  /** Buffer */
89
88
  buffer?: stream.Stream;
90
89
  }
91
- //#endregion
92
- //#region src/middleware/_utils.d.ts
93
90
  type ResOfType<T extends "web" | "ws"> = T extends "ws" ? T extends "web" ? ServerResponse | Http2ServerResponse | Socket : Socket : T extends "web" ? ServerResponse | Http2ServerResponse : never;
94
91
  type ProxyMiddleware<T extends ServerResponse | Http2ServerResponse | Socket> = (req: IncomingMessage | Http2ServerRequest, res: T, opts: ProxyServerOptions & {
95
92
  target: URL | ProxyTargetDetailed;
96
93
  forward: URL;
97
94
  }, 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
95
  interface ProxyServerEventMap<Req extends http__default.IncomingMessage | http2.Http2ServerRequest = http__default.IncomingMessage, Res extends http__default.ServerResponse | http2.Http2ServerResponse = http__default.ServerResponse> {
101
96
  error: [err: Error, req?: Req, res?: Res | net__default.Socket, target?: URL | ProxyTarget];
102
97
  start: [req: Req, res: Res, target: URL | ProxyTarget];
@@ -126,8 +121,9 @@ declare class ProxyServer<Req extends http__default.IncomingMessage | http2.Http
126
121
  * A function that wraps the object in a webserver, for your convenience
127
122
  * @param port - Port to listen on
128
123
  * @param hostname - The hostname to listen on
124
+ * @param listeningListener - A callback function that is called when the server starts listening
129
125
  */
130
- listen(port: number, hostname?: string): this;
126
+ listen(port: number, hostname?: string, listeningListener?: () => void): this;
131
127
  /**
132
128
  * A function that closes the inner webserver and stops listening on given port
133
129
  */
@@ -146,7 +142,7 @@ declare class ProxyServer<Req extends http__default.IncomingMessage | http2.Http
146
142
  type NextFunction<T = (err?: any) => void> = T;
147
143
  interface RequestHandler<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse, TNext = NextFunction> {
148
144
  (req: TReq, res: TRes, next?: TNext): Promise<void>;
149
- upgrade: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
145
+ upgrade: (req: TReq, socket: net.Socket, head: Buffer) => void;
150
146
  }
151
147
  type Filter<TReq extends http.IncomingMessage = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
152
148
  interface Plugin<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> {
@@ -164,6 +160,9 @@ interface OnProxyEvent<TReq extends http.IncomingMessage = http.IncomingMessage,
164
160
  econnreset?: (err: Error, req: TReq, res: TRes, target: string | Partial<URL>) => void;
165
161
  }
166
162
  type Logger = Pick<Console, 'info' | 'warn' | 'error'>;
163
+ type PathRewriteConfig<TReq extends http.IncomingMessage = http.IncomingMessage> = {
164
+ [regexp: string]: string;
165
+ } | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise<string>);
167
166
  interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes extends http.ServerResponse = http.ServerResponse> extends ProxyServerOptions {
168
167
  /**
169
168
  * Narrow down requests to proxy or not.
@@ -185,9 +184,7 @@ interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes
185
184
  * ```
186
185
  * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
187
186
  */
188
- pathRewrite?: {
189
- [regexp: string]: string;
190
- } | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise<string>);
187
+ pathRewrite?: PathRewriteConfig<TReq>;
191
188
  /**
192
189
  * Access the internal http-proxy server instance to customize behavior
193
190
  *
@@ -242,9 +239,7 @@ interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes
242
239
  * ```
243
240
  * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md
244
241
  */
245
- router?: {
246
- [hostOrPath: string]: ProxyServerOptions['target'];
247
- } | ((req: TReq) => ProxyServerOptions['target']) | ((req: TReq) => Promise<ProxyServerOptions['target']>);
242
+ router?: Record<string, ProxyServerOptions['target']> | ((req: TReq) => ProxyServerOptions['target']) | ((req: TReq) => Promise<ProxyServerOptions['target']>);
248
243
  /**
249
244
  * Log information from http-proxy-middleware
250
245
  * @example
@@ -259,6 +254,82 @@ interface Options<TReq extends http.IncomingMessage = http.IncomingMessage, TRes
259
254
  logger?: Logger;
260
255
  }
261
256
 
257
+ /**
258
+ * Create proxy middleware for Express-like servers. ([list of servers with examples](https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md))
259
+ *
260
+ * @example Basic proxy to a single target.
261
+ * ```ts
262
+ * import { createProxyMiddleware } from 'http-proxy-middleware';
263
+ *
264
+ * const proxy = createProxyMiddleware({
265
+ * target: 'http://www.example.org',
266
+ * changeOrigin: true,
267
+ * });
268
+ * ```
269
+ *
270
+ * @example Proxy only matching paths and rewrite the forwarded path.
271
+ * ```ts
272
+ * import { createProxyMiddleware } from 'http-proxy-middleware';
273
+ *
274
+ * const proxy = createProxyMiddleware({
275
+ * target: 'http://localhost:3000',
276
+ * pathFilter: '/api',
277
+ * pathRewrite: {
278
+ * '^/api/': '/',
279
+ * },
280
+ * });
281
+ * ```
282
+ *
283
+ * @example Native path rewrite by mounting at a route (alternative to `pathRewrite`).
284
+ * ```ts
285
+ * import express from 'express';
286
+ * import { createProxyMiddleware } from 'http-proxy-middleware';
287
+ *
288
+ * const app = express();
289
+ * app.use(
290
+ * '/users',
291
+ * createProxyMiddleware({
292
+ * target: 'http://jsonplaceholder.typicode.com/users',
293
+ * changeOrigin: true,
294
+ * }),
295
+ * );
296
+ * ```
297
+ *
298
+ * @example Use framework-specific request/response types (Express).
299
+ * ```ts
300
+ * import type { Request, Response } from 'express';
301
+ * import { createProxyMiddleware } from 'http-proxy-middleware';
302
+ *
303
+ * const proxy = createProxyMiddleware<Request, Response>({
304
+ * target: 'http://www.example.org/api',
305
+ * changeOrigin: true,
306
+ * });
307
+ * ```
308
+ *
309
+ * @example Intercept and modify a proxied response body.
310
+ * ```ts
311
+ * import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
312
+ *
313
+ * const proxy = createProxyMiddleware({
314
+ * target: 'http://www.example.org',
315
+ * selfHandleResponse: true,
316
+ * on: {
317
+ * proxyRes: responseInterceptor(async (responseBuffer) => {
318
+ * const response = responseBuffer.toString('utf8');
319
+ * return response.replace('Hello', 'Goodbye');
320
+ * }),
321
+ * },
322
+ * });
323
+ * ```
324
+ *
325
+ * @see https://github.com/chimurai/http-proxy-middleware/
326
+ * @see https://github.com/chimurai/http-proxy-middleware/#basic-usage
327
+ * @see https://github.com/chimurai/http-proxy-middleware/#intercept-and-manipulate-responses
328
+ * @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/servers.md
329
+ * @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathFilter.md
330
+ * @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
331
+ * @see https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/response-interceptor.md
332
+ */
262
333
  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>;
263
334
 
264
335
  /**
@@ -1 +1 @@
1
- {"name":"http-proxy-middleware","author":"Steven Chim","version":"4.0.0-beta.3","license":"MIT","types":"index.d.ts","type":"module"}
1
+ {"name":"http-proxy-middleware","author":"Steven Chim","version":"4.0.0-beta.5","license":"MIT","types":"index.d.ts","type":"module"}