-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_proxy.js
52 lines (41 loc) · 1.06 KB
/
setup_proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var env = process.env;
if (!env['http_proxy']) return;
var localUrls = [
'http://localhost',
'https://localhost',
'localhost',
'http://127.0.0.1',
'https://127.0.0.1',
'127.0.0.1'
];
var url = require('url');
var tunnel = require('tunnel');
var proxy = url.parse(env['http_proxy']);
var tunnelingAgent = tunnel.httpsOverHttp({
proxy: {
host: 'p-goodway.rd.francetelecom.fr',
port: 3128
}
});
var https = require('https');
var http = require('http');
var oldhttpsreq = https.request;
https.request = function (options, callback) {
if (localUrls.some(function (u) {
return ~u.indexOf(options.host);
})){
return oldhttpsreq.apply(https, arguments);
}
options.agent = tunnelingAgent;
return oldhttpsreq.call(null, options, callback);
};
var oldhttpreq = http.request;
http.request = function (options, callback) {
if (localUrls.some(function (u) {
return ~u.indexOf(options.host);
})){
return oldhttpreq.apply(http, arguments);
}
options.agent = tunnelingAgent;
return oldhttpreq.call(null, options, callback);
};