diff --git a/src/axios.ts b/src/axios.ts index be49d6ca..8c938259 100644 --- a/src/axios.ts +++ b/src/axios.ts @@ -1,11 +1,24 @@ import axios, { AxiosRequestConfig, AxiosError, AxiosResponse } from 'axios'; +import http from 'http'; +import https from 'https'; import emitter from './emitter'; +const agentOptions = { + keepAlive: true, + maxSockets: 100, // Maximum number of sockets to allow per host. Defaults to Infinity. + maxFreeSockets: 10, + freeSocketTimeout: 60000, // // Maximum number of sockets to leave open for 60 seconds in a free state. Only relevant if keepAlive is set to true. Defaults to 256. + socketActiveTTL: 1000 * 60 * 10, +}; + const axios_ = axios.create({ responseType: 'json', headers: { 'Content-Type': 'application/json;charset=utf-8', }, + // keepAlive pools and reuses TCP connections, so it's faster + httpAgent: new http.Agent(agentOptions), + httpsAgent: new https.Agent(agentOptions), }); axios_.interceptors.request.use(