Add extremely alpha typings for http-proxy-middleware

This commit is contained in:
Zebulon McCorkle
2017-06-27 19:07:05 -04:00
parent 56c3605c2f
commit 686775b8d6
3 changed files with 112 additions and 0 deletions

View 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
View 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;

View 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"
]
}