Merge pull request #1179 from automatisch/add-http-proxy-agent

fix(axios): incorporate http(s)-proxy-agents
This commit is contained in:
Ömer Faruk Aydın
2023-07-24 15:40:22 +03:00
committed by GitHub
7 changed files with 61 additions and 3 deletions

View File

@@ -50,6 +50,8 @@
"graphql-type-json": "^0.3.2",
"handlebars": "^4.7.7",
"http-errors": "~1.6.3",
"http-proxy-agent": "^7.0.0",
"https-proxy-agent": "^7.0.1",
"jsonwebtoken": "^9.0.0",
"knex": "^2.4.0",
"lodash.get": "^4.4.2",

View File

@@ -0,0 +1,24 @@
import axios, { AxiosRequestConfig } from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { HttpProxyAgent } from 'http-proxy-agent';
const config: AxiosRequestConfig = {};
const httpProxyUrl = process.env.http_proxy;
const httpsProxyUrl = process.env.https_proxy;
const supportsProxy = httpProxyUrl || httpsProxyUrl;
if (supportsProxy) {
if (httpProxyUrl) {
config.httpAgent = new HttpProxyAgent(process.env.http_proxy);
}
if (httpsProxyUrl) {
config.httpsAgent = new HttpsProxyAgent(process.env.https_proxy);
}
config.proxy = false;
}
const axiosWithProxyInstance = axios.create(config);
export default axiosWithProxyInstance;

View File

@@ -1,3 +1,4 @@
// TODO: replace with axios-with-proxy when needed
import axios from 'axios';
import appConfig from '../../config/app';
import { DateTime } from 'luxon';

View File

@@ -1,3 +1,4 @@
// TODO: replace with axios-with-proxy
import axios from 'axios';
import appConfig from '../config/app';
import memoryCache from 'memory-cache';

View File

@@ -1,8 +1,10 @@
import axios, { AxiosRequestConfig } from 'axios';
export { AxiosInstance as IHttpClient } from 'axios';
import { IHttpClientParams } from '@automatisch/types';
import { URL } from 'url';
import { AxiosRequestConfig } from 'axios';
import { URL } from 'node:url';
export { AxiosInstance as IHttpClient } from 'axios';
import HttpError from '../../errors/http';
import axios from '../axios-with-proxy';
const removeBaseUrlForAbsoluteUrls = (
requestConfig: AxiosRequestConfig