[http-proxy] update TargetUrl (#41321)

* [http-proxy] update TargetUrl

* test + lint

* more

* add the contrib

* typo
This commit is contained in:
Samuel Bodin 2020-01-09 20:21:21 +01:00 committed by Armando Aguirre
parent 77b0d0fd9a
commit 7c20e8a02f
2 changed files with 41 additions and 2 deletions

View File

@ -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'
}
});

View File

@ -4,6 +4,7 @@
// Florian Oellerich <https://github.com/Raigen>
// Daniel Schmidt <https://github.com/DanielMSchmidt>
// Jordan Abreu <https://github.com/jabreu610>
// Samuel Bodin <https://github.com/bodinsamuel>
// 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<url.Url>;
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. */