Como configurar um proxy para got
A maneira mais fácil de configurar um proxy para a biblioteca
Pode ser
got
é usar o pacote auxiliar httpAgent.Pode ser
hpagent
ou https-proxy-agent
. Nós vamos olhar para ambos.hpagent
Primeiro instale o pacote:
npm i hpagent
Então você precisa passar a instância
HttpsProxyAgent
para a configuração 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
Primeiro instale o pacote:
npm i https-proxy-agent
Então você precisa passar a instância
HttpsProxyAgent
para a configuração 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); })();