Cómo configurar un proxy para got
La forma más fácil de configurar un proxy para la biblioteca
Puede ser
got es usar el paquete auxiliar httpAgent.Puede ser
hpagent o https-proxy-agent. Examinaremos ambos.hpagent
Primero instale el paquete:
npm i hpagent
Luego, debe pasar la instancia
HttpsProxyAgent a la configuración got:import got from 'got';
import { HttpsProxyAgent } from 'hpagent';
const httpsProxyAgent = new HttpsProxyAgent({proxy: 'http://127.0.0.1:8080'});
const options = { agent: { https: httpsProxyAgent } };
(async () => {
let response = await got('https://example.com', options);
console.log(response.body);
})();
https-proxy-agent
Primero instale el paquete:
npm i https-proxy-agent
Luego, debe pasar la instancia
HttpsProxyAgent a la configuración got:import got from 'got';
import HttpsProxyAgent from 'https-proxy-agent';
const httpsProxyAgent = new HttpsProxyAgent('http://127.0.0.1:8080');
const options = { agent: { https: httpsProxyAgent } };
(async () => {
let response = await got('https://example.com', options);
console.log(response.body);
})();


