From 9fc72a20c7da686bb20cbb7b977ccfed59c94cd0 Mon Sep 17 00:00:00 2001 From: Jeff Barczewski Date: Wed, 8 Jul 2020 12:11:00 -0500 Subject: [PATCH] add optional `proxy` config property This is passed through to axios to allow the full range of proxy config and override capability. By default axios looks at environment variables http_proxy and https_proxy to determine if proxy should be used. If these are not set then it will default off. To force axios to not use the env variables, use `proxy: false` To force different proxy values (overriding env variables) provide an object compatible with axios like ```js proxy: { host: '127.0.0.1', port: 9000, auth: { username: 'mikeymike', password: 'rapunz3l' } } ``` See https://github.com/axios/axios#config-defaults for full details about what is allowed by axios. --- README.md | 11 +++++++++++ lib/wait-on.js | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a64fd7..175ad7d 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,17 @@ var opts = { /* strings or binaries */ ], passphrase: 'yourpassphrase', + proxy: false /* OR proxy config as defined in axios. + If not set axios detects proxy from env vars http_proxy and https_proxy + https://github.com/axios/axios#config-defaults + { + host: '127.0.0.1', + port: 9000, + auth: { + username: 'mikeymike', + password: 'rapunz3l' + } + } */, auth: { user: 'theuser', // or username pass: 'thepassword', // or password diff --git a/lib/wait-on.js b/lib/wait-on.js index cbc910c..9e271bf 100644 --- a/lib/wait-on.js +++ b/lib/wait-on.js @@ -43,12 +43,12 @@ const WAIT_ON_SCHEMA = Joi.object({ cert: [Joi.string(), Joi.binary()], key: [Joi.string(), Joi.binary(), Joi.object()], passphrase: Joi.string(), + proxy: [Joi.boolean(), Joi.object()], auth: Joi.object({ username: Joi.string(), password: Joi.string(), }), strictSSL: Joi.boolean().default(false), - ignoreProxy: Joi.boolean().default(false), followRedirect: Joi.boolean().default(true), // HTTP 3XX responses headers: Joi.object(), }); @@ -265,10 +265,10 @@ function createHTTP$({ validatedOpts, output }, resource) { followRedirect, httpTimeout: timeout, interval, + proxy, reverse, simultaneous, strictSSL: rejectUnauthorized, - ignoreProxy, } = validatedOpts; const method = HTTP_GET_RE.test(resource) ? 'get' : 'head'; const url = resource.replace('-get:', ':'); @@ -284,9 +284,9 @@ function createHTTP$({ validatedOpts, output }, resource) { ...pick(['ca', 'cert', 'key', 'passphrase'], validatedOpts), }), ...(followRedirect ? {} : { maxRedirects: 0 }), // defaults to 5 (enabled) + ...(proxy && { proxy }), ...(timeout && { timeout }), ...urlSocketOptions, - ...(ignoreProxy ? { proxy: false }: {}), // axios no proxy method, // by default it provides full response object // validStatus is 2xx unless followRedirect is true (default)