Skip to content

Commit

Permalink
removed axios dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
massimocandela committed Dec 24, 2023
1 parent 1aa1cb9 commit 77e72d5
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 223 deletions.
302 changes: 108 additions & 194 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
],
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.5",
"@babel/core": "^7.23.6",
"@babel/node": "^7.22.19",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/preset-env": "^7.23.5",
"@babel/preset-env": "^7.23.6",
"chai": "^4.3.10",
"chai-subset": "^1.6.0",
"mocha": "^10.2.0",
Expand All @@ -58,8 +58,7 @@
"syslogd": "^1.1.2"
},
"dependencies": {
"@sentry/node": "^7.84.0",
"axios": "=0.27.2",
"@sentry/node": "^7.91.0",
"batch-promises": "^0.0.3",
"brembo": "^2.1.0",
"deepmerge": "^4.3.1",
Expand All @@ -76,12 +75,13 @@
"nodemailer": "^6.9.7",
"object-fingerprint": "^1.0.2",
"path": "^0.12.7",
"redaxios": "^0.5.1",
"restify": "github:massimocandela/node-restify",
"rpki-validator": "^2.13.8",
"rpki-validator": "^2.13.9",
"semver": "^7.5.4",
"syslog-client": "^1.1.1",
"uuid": "^9.0.1",
"ws": "^8.14.2",
"ws": "^8.15.1",
"yargs": "^17.7.2"
},
"pkg": {
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "axios";
import axios from "redaxios";

export default class Config {
static configVersion = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import axios from "axios";
import axios from "redaxios";
import axiosEnrich from "../utils/axiosEnrich";

export default class Connector {
Expand Down
2 changes: 1 addition & 1 deletion src/generatePrefixesList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "axios";
import axios from "redaxios";
import url from "url";
import brembo from "brembo";
import merge from "deepmerge";
Expand Down
2 changes: 1 addition & 1 deletion src/monitors/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import axios from "axios";
import axios from "redaxios";
import axiosEnrich from "../utils/axiosEnrich";

export default class Monitor {
Expand Down
2 changes: 1 addition & 1 deletion src/processMonitors/uptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import axios from "axios";
import axios from "redaxios";
import env from "../env";
import axiosEnrich from "../utils/axiosEnrich";

Expand Down
2 changes: 1 addition & 1 deletion src/reports/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import moment from "moment";
import brembo from "brembo";
import axios from "axios";
import axios from "redaxios";
import axiosEnrich from "../utils/axiosEnrich";
import RpkiValidator from "rpki-validator";

Expand Down
23 changes: 9 additions & 14 deletions src/utils/axiosEnrich.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import md5 from "md5";
const attempts = {};
const numAttempts = 2;

const retry = function (axios, error) {
const retry = function (axios, error, params) {
return new Promise((resolve, reject) => {
setTimeout(() => {
const key = md5(JSON.stringify(error.config));
const key = md5(JSON.stringify(params));
attempts[key] = attempts[key] || 0;
attempts[key]++;
if (attempts[key] <= numAttempts) {
resolve(axios.request(error.config));
resolve(axios.request(params));
} else {
reject(error);
}
Expand All @@ -20,6 +20,10 @@ const retry = function (axios, error) {

export default function(axios, httpsAgent, userAgent) {

axios.defaults ??= {};
axios.defaults.headers ??= {};
axios.defaults.headers.common ??= {};

// Set agent/proxy
if (httpsAgent) {
axios.defaults.httpsAgent = httpsAgent;
Expand All @@ -36,15 +40,6 @@ export default function(axios, httpsAgent, userAgent) {
'Accept-Encoding': 'gzip'
};

// Retry
axios.interceptors.response.use(
response => response,
error => {
if (error.config) {
return retry(axios, error);
}
return Promise.reject(error);
});

return axios;
return params => axios(params)
.catch(error => retry(axios, error, params));
}
2 changes: 1 addition & 1 deletion src/utils/rpkiUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import RpkiValidator from "rpki-validator";
import fs from "fs";
import axiosEnrich from "./axiosEnrich";
import axios from "axios";
import axios from "redaxios";
import moment from "moment";
import fingerprint from "object-fingerprint";

Expand Down
2 changes: 1 addition & 1 deletion tests/2_alerting.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const cacheCloneDirectory = "tests/.cache_clone/";
const asyncTimeout = 120000;
global.EXTERNAL_VERSION_FOR_TEST = "0.0.1";
global.EXTERNAL_CONFIG_FILE = volume + "config.test.yml";
const axios = require("axios");
const axios = require("redaxios");

const worker = require("../index");
const pubSub = worker.pubSub;
Expand Down
2 changes: 1 addition & 1 deletion tests/3_uptimemonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

const chai = require("chai");
const chaiSubset = require('chai-subset');
const axios = require('axios');
const axios = require('redaxios');
chai.use(chaiSubset);
const expect = chai.expect;
const volume = "volumetests/";
Expand Down

0 comments on commit 77e72d5

Please sign in to comment.