Merge pull request #26 from mattn/proxy

support proxy.
This commit is contained in:
billy gates
2012-09-25 13:55:22 -07:00
2 changed files with 16 additions and 3 deletions

View File

@@ -193,6 +193,11 @@ Package.prototype.download = function () {
var src = url.parse(this.assetUrl);
var req = src.protocol === 'https:' ? https : http;
if (process.env.HTTP_PROXY) {
src = url.parse(process.env.HTTP_PROXY);
src.path = this.assetUrl;
}
tmp.dir(function (err, tmpPath) {
var file = fs.createWriteStream(path.join((this.path = tmpPath), 'index' + this.assetType));
@@ -293,7 +298,11 @@ Package.prototype.cache = function () {
return this.emit('cache');
}
template('action', { name: 'caching', shizzle: this.gitUrl }).on('data', this.emit.bind(this, 'data'));
var cp = spawn('git', ['clone', this.gitUrl, this.path]);
var url = this.gitUrl;
if (process.env.HTTP_PROXY) {
url = url.replace(/^git:/, 'https:');
}
var cp = spawn('git', ['clone', url, this.path]);
cp.stderr.setEncoding('utf8');
cp.stderr.on('data', this.emit.bind(this, 'data'));
cp.on('close', function (code) {
@@ -413,4 +422,4 @@ Package.prototype.__defineGetter__('localPath', function () {
return path.join(process.cwd(), config.directory, this.name);
});
module.exports = Package;
module.exports = Package;

View File

@@ -11,6 +11,10 @@ var _ = require('lodash');
var endpoint = 'https://bower.herokuapp.com/packages';
if (process.env.HTTP_PROXY) {
request = request.defaults({'proxy': process.env.HTTP_PROXY});
}
exports.lookup = function (name, callback) {
request.get(endpoint + '/' + encodeURIComponent(name), function (err, response, body) {
if (err || response.statusCode !== 200) return callback(err || new Error(name + ' not found'));
@@ -65,4 +69,4 @@ exports.all = function (callback) {
request.get(endpoint, function (err, response, body) {
callback(err, body && JSON.parse(body));
});
};
};