node axios does not force the use of environment variables

const axios = require('axios')
const { httpsOverHttp, httpOverHttp } = require('tunnel-agent')

const TUNNEL_OPTIONS = { proxy: { port: } }

axios.interceptors.request.use(function (config) {
  config.proxy = false // Force disable proxy configuration from environment variables
  config.httpAgent = httpOverHttp(TUNNEL_OPTIONS)
  config.httpsAgent = httpsOverHttp(TUNNEL_OPTIONS)
  return config
})
const axios = require('axios')
// const { httpsOverHttp, httpOverHttp } = require('tunnel-agent')
// const TUNNEL_OPTIONS = { proxy: { port: } }
axios.interceptors.request.use(function (config) {
  config.proxy = {
    protocol: 'http',
    host: '127.0.0.1',
    port: 10,
    // auth: {
    //   username: 'mikeymike',
    //   password: 'rapunz3l'
    // }
  }// Force disable proxy configuration from environment variables
  // config.httpAgent = httpOverHttp(TUNNEL_OPTIONS)
  // config.httpsAgent = httpsOverHttp(TUNNEL_OPTIONS)
   return config
})
axios.get('http://lininn.cn').then(res=>{
  console.log(res)
})
This method prevents the business from modifying the proxy and agent configuration parameters, but it is indeed a feasible approach. $ node --require ./one.js

评论

暂无评论。

登录后可发表评论。