访问

2017-07-17 73 views
0

好日子大家,我遇到了如下问题:访问

我在一个项目(也没有我的)有gulpfile.js(不是我)。 重新建设该项目过程中出现了这个错误:

Error: connect ETIMEDOUT 87.98.253.108:443 
    at Object.exports._errnoException (util.js:1018:11) 
    at exports._exceptionWithHostPort (util.js:1041:20) 
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14) 

这里:

gulp.task('get-composer', function(callback) { 
    // Check if Composer already in place 
    if (fs.existsSync('./composer.phar')) { 
     callback(null); 

     return; 
    } 

    // Get installer from the internet 
    https.get(config.getComposerUrl, function(response) { 
     // Run PHP to install Composer 
     var php = exec(config.phpBin, function(error, stdout, stderr) { 
      callback(error ? stderr : null); 
     }); 
     // Pass installer code to PHP via STDIN 
     response.pipe(php.stdin); 
    }); 
}); 

现在我得到这个错误,因为我坐在后面的企业代理服务器,我不能fugure out是如何告诉gulp使用我的代理的所有请求。 我见过gulp.task(....)和代理中间件等一些解决方案,但这不是我所需要的。 我还看到一个简单的解决方案,这是这样的:

var proxy = http_proxy || http:\\username:[email protected]; 

某处,或类似的东西,但我似乎无法找到它或正确记住它。

+0

如果有人有任何想法,我真的很需要帮助。我仍然无法弄清楚。 –

回答

0

对于那里的每个人,我终于找到了答案。长话短说我实际上需要使用http-proxy-agent。 我发布了我在https://www.npmjs.com/package/http-proxy-agent这里找到的示例代码。

var url = require('url'); 
var http = require('http'); 
var HttpsProxyAgent = require('https-proxy-agent'); 

// HTTP/HTTPS proxy to connect to 
var proxy = process.env.http_proxy || 'http://168.63.76.32:3128'; 
console.log('using proxy server %j', proxy); 

// HTTP endpoint for the proxy to connect to 
var endpoint = process.argv[2] || 'http://nodejs.org/api/'; 
console.log('attempting to GET %j', endpoint); 
var opts = url.parse(endpoint); 

// create an instance of the `HttpProxyAgent` class with the proxy server information 
var agent = new HttpsProxyAgent(proxy); 
opts.agent = agent; 

https.get(opts, function (res) { 
    console.log('"response" event!', res.headers); 
    res.pipe(process.stdout); 
}); 

该代码很容易使用和更改您的需求。 我希望这个例子可以帮助其他人,像我一样被困住。

+0

我想这个问题可以删除。 –