Skip to content

Commit

Permalink
fix bug in new getAxios preventing the same API from being loaded con…
Browse files Browse the repository at this point in the history
…sistently
  • Loading branch information
pirog committed Oct 25, 2024
1 parent 8013457 commit 150e490
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 3 additions & 2 deletions utils/get-axios.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
13 changes: 4 additions & 9 deletions utils/legacy-scan.js
Original file line number Diff line number Diff line change
@@ -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()) => {
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 150e490

Please sign in to comment.