mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 06:40:35 +08:00
Add extremely alpha typings for http-proxy-middleware
This commit is contained in:
23
types/http-proxy-middleware/http-proxy-middleware-tests.ts
Normal file
23
types/http-proxy-middleware/http-proxy-middleware-tests.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// Derived from https://github.com/chimurai/http-proxy-middleware#example
|
||||
|
||||
import * as express from 'express';
|
||||
import * as proxy from 'http-proxy-middleware';
|
||||
|
||||
const options = {
|
||||
target: 'http://www.example.org',
|
||||
changeOrigin: true,
|
||||
ws: true,
|
||||
pathRewrite: {
|
||||
'^/api/old-path': '/api/new-path',
|
||||
'^/api/remove/path': '/path'
|
||||
},
|
||||
router: {
|
||||
'dev.localhost:3000': 'http://localhost:8000'
|
||||
}
|
||||
};
|
||||
|
||||
const myProxy = proxy(options);
|
||||
|
||||
const app = express();
|
||||
app.use('/api', myProxy);
|
||||
app.listen(3000);
|
||||
67
types/http-proxy-middleware/index.d.ts
vendored
Normal file
67
types/http-proxy-middleware/index.d.ts
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// Type definitions for http-proxy-middleware
|
||||
// Project: https://github.com/chimurai/http-proxy-middleware
|
||||
// Definitions by: Zebulon McCorkle <https://github.com/zebMcCorkle/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
/// <reference types="connect" />
|
||||
|
||||
import * as http from 'http';
|
||||
import * as net from 'net';
|
||||
import * as tls from 'tls';
|
||||
import * as connect from 'connect';
|
||||
|
||||
declare function proxy(config: proxy.Config): proxy.Proxy;
|
||||
declare function proxy(contextOrUri: string, config: proxy.Config): proxy.Proxy;
|
||||
|
||||
declare namespace proxy {
|
||||
type Logger = (...objs: any[]) => void;
|
||||
export interface LogProvider {
|
||||
log: Logger,
|
||||
debug?: Logger,
|
||||
info?: Logger,
|
||||
warn?: Logger,
|
||||
error?: Logger,
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
pathRewrite?: { [regexp: string]: string } | ((path: string, req: http.IncomingMessage) => string),
|
||||
router?: { [hostOrPath: string]: string } | ((req: http.IncomingMessage) => string),
|
||||
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent',
|
||||
logProvider?: (provider: LogProvider) => LogProvider,
|
||||
|
||||
onError?: connect.HandleFunction,
|
||||
onProxyRes?: (proxyRes: http.ServerResponse, req: http.IncomingMessage, res: http.ServerResponse) => void,
|
||||
onProxyReq?: (proxyReq: http.ClientRequest, req: http.IncomingMessage, res: http.ServerResponse) => void,
|
||||
onProxyReqWs?: (proxyReq: http.ClientRequest, req: http.IncomingMessage, socket: any, options: any, head: any) => void, // TODO: Figure out the types of the last 3
|
||||
onOpen?: (proxySocket: net.Socket) => void,
|
||||
onClose?: (res: http.ServerResponse, socket: net.Socket) => void,
|
||||
|
||||
target?: string,
|
||||
forward?: string,
|
||||
agent?: http.Agent,
|
||||
ssl?: tls.TlsOptions,
|
||||
ws?: boolean,
|
||||
xfwd?: boolean,
|
||||
secure?: boolean,
|
||||
toProxy?: boolean,
|
||||
prependPath?: boolean,
|
||||
ignorePath?: boolean,
|
||||
localAddress?: string,
|
||||
changeOrigin?: boolean,
|
||||
auth?: string,
|
||||
hostRewrite?: any, // TODO
|
||||
autoRewrite?: any, // TODO
|
||||
protocolRewrite?: any, // TODO
|
||||
cookieDomainRewrite?: false | string | { [domain: string]: string },
|
||||
headers?: { [header: string]: string },
|
||||
proxyTimeout?: number,
|
||||
}
|
||||
|
||||
export interface Proxy extends connect.NextHandleFunction {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export = proxy;
|
||||
22
types/http-proxy-middleware/tsconfig.json
Normal file
22
types/http-proxy-middleware/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"http-proxy-middleware-tests.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user