From 150e490d7ac6a7e4f9ea066624a2678b21e962db Mon Sep 17 00:00:00 2001 From: Mike Pirog Date: Fri, 25 Oct 2024 09:09:35 -0400 Subject: [PATCH] fix bug in new getAxios preventing the same API from being loaded consistently --- utils/get-axios.js | 5 +++-- utils/legacy-scan.js | 13 ++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/utils/get-axios.js b/utils/get-axios.js index ce64ba0b1..a853fb235 100644 --- a/utils/get-axios.js +++ b/utils/get-axios.js @@ -1,9 +1,10 @@ 'use strict'; -const {create} = require('axios'); +const axios = require('axios'); + const {HttpAgent, HttpsAgent} = require('@npmcli/agent'); -module.exports = (opts = {}, httpOpts = {}, httpsOpts = {}) => create({ +module.exports = (opts = {}, httpOpts = {}, httpsOpts = {}) => axios.create({ httpAgent: new HttpAgent({family: 4, ...httpOpts}), httpsAgent: new HttpsAgent({family: 4, ...httpsOpts}), ...opts, diff --git a/utils/legacy-scan.js b/utils/legacy-scan.js index 3c3a51f7a..ad2e018de 100644 --- a/utils/legacy-scan.js +++ b/utils/legacy-scan.js @@ -1,15 +1,10 @@ // Modules const _ = require('lodash'); -const Log = require('../lib/logger'); -const Promise = require('../lib/promise'); +const Log = require('./../lib/logger'); +const Promise = require('./../lib/promise'); -/* - * Helper to load request library - * We do this for testing so we can stub axios and ensure it isn't auto cached - * via require when we new Lando() - */ -const requestClient = () => require('../utils/get-axios')({maxRedirects: 0}, {}, {rejectUnauthorized: false}); +const axios = require('../utils/get-axios')({maxRedirect: 0}, {}, {rejectUnauthorized: false}); // We make this module into a function so we can pass in a logger module.exports = (log = new Log()) => { @@ -52,7 +47,7 @@ module.exports = (log = new Log()) => { // If URL contains a wildcard then immediately set fulfill with yellow status if (_.includes(url, '*')) return Promise.resolve(setOK(url)); // Send REST request. - return requestClient().get(url) + return axios.get(url) // Return good responses .then(response => { log.debug('scan response %s received', url, {