TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
872 stars 229 forks source link

latest version of proxy-agent does not work with aws-sdk #232

Closed renperez-cpi closed 10 months ago

renperez-cpi commented 10 months ago

seems like any version of proxy-agent except 5.0.0 is the only one working with aws-sdk. unfortunately 5.0.0 has critical vulnerability because of vm2 dependency. can we fix the latest version to be compatible with aws-sdk. @TooTallNate please advice. thank you

/app/config/aws-config.js:12 agent: proxy(process.env.HTTP_PROXY) TypeError: proxy is not a function at Object. (/app/config/aws-config.js:12:14) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at Module.require (node:internal/modules/cjs/loader:1143:19) at require (node:internal/modules/cjs/helpers:110:18) at Object. (/app/config/index.js:11:19) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) Node.js v18.16.1

TooTallNate commented 10 months ago

Could you share your code?

You are probably not importing proxy-agent module correctly. The API changed between v5 and v6:

// v5
import ProxyAgent from 'proxy-agent';

vs.

// v6
import { ProxyAgent } from 'proxy-agent';
renperez-cpi commented 10 months ago

@TooTallNate

'use strict'

/* eslint-disable no-process-env */
const AWS = require('aws-sdk')
const clonedeep = require('lodash/cloneDeep')
const merge = require('lodash/merge')
const proxy = require('proxy-agent')

if (process.env.HTTP_PROXY !== '') {
  AWS.config.update({
    httpOptions: {
      agent: proxy(process.env.HTTP_PROXY)
    }
  })
}
renperez-cpi commented 10 months ago

@TooTallNate i fixed it by using this instead. thank you

const ProxyAgent = require('proxy-agent');

const proxy = process.env.HTTP_PROXY;
if (proxy) {
  const proxyAgent = new ProxyAgent(proxy);
  AWS.config.update({
    httpOptions: {
      agent: proxyAgent,
    },
  });
}