1 |
|
2 |
|
3 |
|
4 |
|
5 | import type * as http from 'http';
|
6 | import type * as httpProxy from 'http-proxy';
|
7 | import type * as net from 'net';
|
8 | export type NextFunction<T = (err?: any) => void> = T;
|
9 | export interface RequestHandler<TReq = http.IncomingMessage, TRes = http.ServerResponse, TNext = NextFunction> {
|
10 | (req: TReq, res: TRes, next?: TNext): Promise<void>;
|
11 | upgrade: (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
|
12 | }
|
13 | export type Filter<TReq = http.IncomingMessage> = string | string[] | ((pathname: string, req: TReq) => boolean);
|
14 | export interface Plugin<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
15 | (proxyServer: httpProxy<TReq, TRes>, options: Options<TReq, TRes>): void;
|
16 | }
|
17 | export interface OnProxyEvent<TReq = http.IncomingMessage, TRes = http.ServerResponse> {
|
18 | error?: httpProxy.ErrorCallback<Error, TReq, TRes>;
|
19 | proxyReq?: httpProxy.ProxyReqCallback<http.ClientRequest, TReq, TRes>;
|
20 | proxyReqWs?: httpProxy.ProxyReqWsCallback<http.ClientRequest, TReq>;
|
21 | proxyRes?: httpProxy.ProxyResCallback<TReq, TRes>;
|
22 | open?: httpProxy.OpenCallback;
|
23 | close?: httpProxy.CloseCallback<TReq>;
|
24 | start?: httpProxy.StartCallback<TReq, TRes>;
|
25 | end?: httpProxy.EndCallback<TReq, TRes>;
|
26 | econnreset?: httpProxy.EconnresetCallback<Error, TReq, TRes>;
|
27 | }
|
28 | export type Logger = Pick<Console, 'info' | 'warn' | 'error'>;
|
29 | export interface Options<TReq = http.IncomingMessage, TRes = http.ServerResponse> extends httpProxy.ServerOptions {
|
30 | /**
|
31 | * Narrow down requests to proxy or not.
|
32 | * Filter on {@link http.IncomingMessage.url `pathname`} which is relative to the proxy's "mounting" point in the server.
|
33 | * Or use the {@link http.IncomingMessage `req`} object for more complex filtering.
|
34 | * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathFilter.md
|
35 | * @since v3.0.0
|
36 | */
|
37 | pathFilter?: Filter<TReq>;
|
38 | /**
|
39 | * Modify request paths before requests are send to the target.
|
40 | * @example
|
41 | * ```js
|
42 | * createProxyMiddleware({
|
43 | * pathRewrite: {
|
44 | * '^/api/old-path': '/api/new-path',
|
45 | * }
|
46 | * });
|
47 | * ```
|
48 | * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/pathRewrite.md
|
49 | */
|
50 | pathRewrite?: {
|
51 | [regexp: string]: string;
|
52 | } | ((path: string, req: TReq) => string | undefined) | ((path: string, req: TReq) => Promise<string>);
|
53 | /**
|
54 | * Access the internal http-proxy server instance to customize behavior
|
55 | *
|
56 | * @example
|
57 | * ```js
|
58 | * createProxyMiddleware({
|
59 | * plugins: [(proxyServer, options) => {
|
60 | * proxyServer.on('error', (error, req, res) => {
|
61 | * console.error(error);
|
62 | * });
|
63 | * }]
|
64 | * });
|
65 | * ```
|
66 | * @link https://github.com/chimurai/http-proxy-middleware#plugins-array
|
67 | * @since v3.0.0
|
68 | */
|
69 | plugins?: Plugin<TReq, TRes>[];
|
70 | /**
|
71 | * Eject pre-configured plugins.
|
72 | * NOTE: register your own error handlers to prevent server from crashing.
|
73 | *
|
74 | * @link https://github.com/chimurai/http-proxy-middleware#ejectplugins-boolean-default-false
|
75 | * @since v3.0.0
|
76 | */
|
77 | ejectPlugins?: boolean;
|
78 | /**
|
79 | * Listen to http-proxy events
|
80 | * @see {@link OnProxyEvent} for available events
|
81 | * @example
|
82 | * ```js
|
83 | * createProxyMiddleware({
|
84 | * on: {
|
85 | * error: (error, req, res, target) => {
|
86 | * console.error(error);
|
87 | * }
|
88 | * }
|
89 | * });
|
90 | * ```
|
91 | * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/proxy-events.md
|
92 | * @since v3.0.0
|
93 | */
|
94 | on?: OnProxyEvent<TReq, TRes>;
|
95 | /**
|
96 | * Dynamically set the {@link Options.target `options.target`}.
|
97 | * @example
|
98 | * ```js
|
99 | * createProxyMiddleware({
|
100 | * router: async (req) => {
|
101 | * return 'http:
|
102 | * }
|
103 | * });
|
104 | * ```
|
105 | * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/router.md
|
106 | */
|
107 | router?: {
|
108 | [hostOrPath: string]: httpProxy.ServerOptions['target'];
|
109 | } | ((req: TReq) => httpProxy.ServerOptions['target']) | ((req: TReq) => Promise<httpProxy.ServerOptions['target']>);
|
110 | /**
|
111 | * Log information from http-proxy-middleware
|
112 | * @example
|
113 | * ```js
|
114 | * createProxyMiddleware({
|
115 | * logger: console
|
116 | * });
|
117 | * ```
|
118 | * @link https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/logger.md
|
119 | * @since v3.0.0
|
120 | */
|
121 | logger?: Logger | any;
|
122 | }
|
123 |
|
\ | No newline at end of file |