forked from chimurai/http-proxy-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
85 lines (73 loc) · 2.57 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
85
/**
* Based on definition by DefinitelyTyped:
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
*/
/* eslint-disable @typescript-eslint/no-empty-interface */
import type * as express from 'express';
import type * as http from 'http';
import type * as httpProxy from 'http-proxy';
import type * as net from 'net';
import type * as url from 'url';
export interface Request extends express.Request {}
export interface Response extends express.Response {}
export interface RequestHandler extends express.RequestHandler {
upgrade?: (req: Request, socket: net.Socket, head: any) => void;
}
export type Filter = string | string[] | ((pathname: string, req: Request) => boolean);
export interface Options extends httpProxy.ServerOptions {
pathRewrite?:
| { [regexp: string]: string }
| ((path: string, req: Request) => string)
| ((path: string, req: Request) => Promise<string>);
router?:
| { [hostOrPath: string]: httpProxy.ServerOptions['target'] }
| ((req: Request) => httpProxy.ServerOptions['target'])
| ((req: Request) => Promise<httpProxy.ServerOptions['target']>);
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
logProvider?: LogProviderCallback;
onError?: OnErrorCallback;
onProxyRes?: OnProxyResCallback;
onProxyReq?: OnProxyReqCallback;
onProxyReqWs?: OnProxyReqWsCallback;
onOpen?: OnOpenCallback;
onClose?: OnCloseCallback;
}
interface LogProvider {
log: Logger;
debug?: Logger;
info?: Logger;
warn?: Logger;
error?: Logger;
}
type Logger = (...args: any[]) => void;
export type LogProviderCallback = (provider: LogProvider) => LogProvider;
/**
* Use types based on the events listeners from http-proxy
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/51504fd999031b7f025220fab279f1b2155cbaff/types/http-proxy/index.d.ts
*/
export type OnErrorCallback = (
err: Error,
req: Request,
res: Response,
target?: string | Partial<url.Url>
) => void;
export type OnProxyResCallback = (
proxyRes: http.IncomingMessage,
req: Request,
res: Response
) => void;
export type OnProxyReqCallback = (
proxyReq: http.ClientRequest,
req: Request,
res: Response,
options: httpProxy.ServerOptions
) => void;
export type OnProxyReqWsCallback = (
proxyReq: http.ClientRequest,
req: Request,
socket: net.Socket,
options: httpProxy.ServerOptions,
head: any
) => void;
export type OnCloseCallback = (proxyRes: Response, proxySocket: net.Socket, proxyHead: any) => void;
export type OnOpenCallback = (proxySocket: net.Socket) => void;