diff --git a/types/http-proxy/http-proxy-tests.ts b/types/http-proxy/http-proxy-tests.ts index 1610befc7d..b75f52056e 100644 --- a/types/http-proxy/http-proxy-tests.ts +++ b/types/http-proxy/http-proxy-tests.ts @@ -25,10 +25,31 @@ http.createServer((req, res) => { proxy.web(req, res); }); -const newProxy = HttpProxy.createProxyServer({ +const newProxyDefault = HttpProxy.createProxyServer({ target: { host: 'localhost', port: '9015' }, ws: true }); + +const newProxyUrl = HttpProxy.createProxyServer({ + target: 'http://localhost:9015' +}); + +const newProxyComplete = HttpProxy.createProxyServer({ + target: { + protocol: 'http:', + host: 'localhost', + port: 9015, + pfx: Buffer.from('foobar'), + hostname: 'localhost.com', + socketPath: '/foo', + passphrase: 'password', + key: 'my-key', + cert: 'my-cert', + ca: 'my-ca', + ciphers: 'my-ciphers', + secureProtocol: 'my-secure-protocol' + } +}); diff --git a/types/http-proxy/index.d.ts b/types/http-proxy/index.d.ts index b9bd3d9b02..55b74c405b 100644 --- a/types/http-proxy/index.d.ts +++ b/types/http-proxy/index.d.ts @@ -4,6 +4,7 @@ // Florian Oellerich // Daniel Schmidt // Jordan Abreu +// Samuel Bodin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -16,8 +17,25 @@ import * as events from "events"; import * as url from "url"; import * as stream from "stream"; +type ProxyTarget = ProxyTargetUrl | ProxyTargetDetailed; + type ProxyTargetUrl = string | Partial; +interface ProxyTargetDetailed { + host: string; + port: number; + protocol?: string; + hostname?: string; + socketPath?: string; + key?: string; + passphrase?: string; + pfx?: Buffer | string; + cert?: string; + ca?: string; + ciphers?: string; + secureProtocol?: string; +} + type ErrorCallback = ( err: Error, req: http.IncomingMessage, @@ -169,7 +187,7 @@ declare class Server extends events.EventEmitter { declare namespace Server { interface ServerOptions { /** URL string to be parsed with the url module. */ - target?: ProxyTargetUrl; + target?: ProxyTarget; /** URL string to be parsed with the url module. */ forward?: ProxyTargetUrl; /** Object to be passed to http(s).request. */