Skip to content
This repository was archived by the owner on Dec 26, 2024. It is now read-only.

Commit f2f60c6

Browse files
author
coco50511
committed
proxyUrl and headers have been added
1 parent ce2df00 commit f2f60c6

3 files changed

Lines changed: 34 additions & 36 deletions

File tree

lib/get-request.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,26 @@ const TESTNET_API_URL_MAP = {
2121
homestead: 'https://api.etherscan.io'
2222
};
2323

24-
module.exports = function(chain, timeout) {
25-
var client = axios.create({
26-
baseURL: pickChainUrl(chain),
24+
module.exports = function(chain, timeout, proxyUrl, headers) {
25+
var param = {
2726
timeout: timeout
28-
});
27+
};
28+
29+
var baseUrl = pickChainUrl(chain);
30+
if (proxyUrl && 0 < proxyUrl.length) {
31+
if (proxyUrl.charAt(proxyUrl.length - 1) == '/') {
32+
baseUrl = proxyUrl + '/' + baseUrl;
33+
} else {
34+
baseUrl = proxyUrl + baseUrl;
35+
}
36+
}
37+
param[baseUrl] = baseUrl;
38+
39+
if (headers) {
40+
param[headers] = headers;
41+
}
42+
43+
var client = axios.create(param);
2944

3045
/**
3146
* @param query

lib/init.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ const account = require('./account');
1414
* @param {string} apiKey - (optional) Your Etherscan APIkey
1515
* @param {string} chain - (optional) Testnet chain keys [ropsten, rinkeby, kovan]
1616
* @param {number} timeout - (optional) Timeout in milliseconds for requests, default 10000
17+
* @param {string} proxyUrl - (optional) The URL of proxy server to avoid CORS
18+
* @param {object} headers - (optional) The object containing custom headers
1719
*/
18-
module.exports = function(apiKey, chain, timeout) {
20+
module.exports = function(apiKey, chain, timeout, proxyUrl, headers) {
1921

2022
if (!apiKey) {
2123
apiKey = 'YourApiKeyToken';
@@ -26,7 +28,7 @@ module.exports = function(apiKey, chain, timeout) {
2628
timeout = 10000;
2729
}
2830

29-
var getRequest = require('./get-request')(chain, timeout);
31+
var getRequest = require('./get-request')(chain, timeout, proxyUrl, headers);
3032

3133
/** @lends module:etherscan/api */
3234
return {

package-lock.json

Lines changed: 11 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)