diff --git a/lib/middleware/proxy.js b/lib/middleware/proxy.js index 6b0fcf730..6d0ef1a7a 100644 --- a/lib/middleware/proxy.js +++ b/lib/middleware/proxy.js @@ -1,3 +1,4 @@ +const dns = require('dns') const url = require('url') const { Agent: httpAgent } = require('http') const { Agent: httpsAgent } = require('https') @@ -41,7 +42,10 @@ function parseProxyConfig (proxies, config) { const port = proxyDetails.port || defaultPorts[proxyDetails.protocol] || config.port const changeOrigin = proxyConfiguration.changeOrigin || false const Agent = protocol === 'https:' ? httpsAgent : httpAgent - const agent = new Agent({ keepAlive: true }) + const agent = new Agent({ + keepAlive: true, + lookup: (hostname, options, callback) => dns.lookup(hostname, { ...options, verbatim: false }, callback) + }) const proxy = httpProxy.createProxyServer({ target: { host: hostname, port, protocol }, xfwd: true, diff --git a/lib/runner.js b/lib/runner.js index 2e04065b6..ede05d48e 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -1,5 +1,6 @@ 'use strict' +const dns = require('dns') const http = require('http') const constant = require('./constants') @@ -74,7 +75,8 @@ function run (cliOptionsOrConfig, done) { method: 'POST', headers: { 'Content-Type': 'application/json' - } + }, + lookup: (hostname, options, callback) => dns.lookup(hostname, { ...options, verbatim: false }, callback) } const request = http.request(options, function (response) { diff --git a/lib/stopper.js b/lib/stopper.js index 964eb5e37..8076178fa 100644 --- a/lib/stopper.js +++ b/lib/stopper.js @@ -1,3 +1,4 @@ +const dns = require('dns') const http = require('http') const cfg = require('./config') const logger = require('./logger') @@ -42,7 +43,8 @@ exports.stop = function (cliOptionsOrConfig, done) { hostname: config.hostname, path: config.urlRoot + 'stop', port: config.port, - method: 'GET' + method: 'GET', + lookup: (hostname, options, callback) => dns.lookup(hostname, { ...options, verbatim: false }, callback) }) request.on('response', function (response) { diff --git a/test/e2e/support/proxy.js b/test/e2e/support/proxy.js index 5bf17c1fd..e78a4544c 100644 --- a/test/e2e/support/proxy.js +++ b/test/e2e/support/proxy.js @@ -8,7 +8,7 @@ module.exports = class Proxy { this.proxyPathRegExp = null this.proxy = httpProxy.createProxyServer({ - target: 'http://localhost:9876' + target: 'http://127.0.0.1:9876' }) this.proxy.on('error', (err) => {