Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Add http.Agent option #100

Merged
merged 2 commits into from
Apr 27, 2020
Merged

Add http.Agent option #100

merged 2 commits into from
Apr 27, 2020

Conversation

rkretzschmar
Copy link
Contributor

- Summary

If you want to use this Netlify JS client behind a corporate proxy, you need to be able to pass a proxy agent, like for example the https-proxy-agent, to the underlying node-fetch. So I basically implemented what was suggested here.

With this, it should also be possible to handle other use cases and situations by using or even creating custom http.Agent implementations.

- Test plan

  • added three ava tests, those and the existing tests still pass
  • successfully tested a Netlify site deployment by implementing this:
const NetlifyAPI = require("netlify");
const HttpsProxyAgent = require("https-proxy-agent");

const proxyUri = "http://username:password@corporate-proxy-hostname:port";
const agent = new HttpsProxyAgent(proxyUri);
const client = new NetlifyAPI("myAccessToken", { agent });

async function deployeSite(siteId, buildDir, opts) {
  return await client.deploy(siteId, buildDir, opts);
}

deployeSite("mySiteId", "dist/my-project-build", {
  draft: true,
}).then((deploy) => console.log(deploy));

- Description for the changelog

  • add option named agent of type http.Agent to NetlifyClient opts, so that something like https-proxy-agent can be passed to the underlying node-fetch.

- A picture of a cute animal (not mandatory but encouraged)

cute proxy animal

@ehmicky ehmicky self-requested a review April 27, 2020 14:51
@ehmicky ehmicky added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Apr 27, 2020
@ehmicky
Copy link
Contributor

ehmicky commented Apr 27, 2020

Thanks @rkretzschmar, this looks great!

Only one thing: would it be possible to add a test using a real http.Agent instance instead of a mock plain object? Even just using the default Node.js Agent. Thanks!

@rkretzschmar
Copy link
Contributor Author

Hi @ehmicky,

thanks for the feedback. I haven't add another test, but replaced the mock agent with the Node.js http.Agent as suggested and passed some arbitrary options to it's constructor.

Hope that's what you was asking for?

Best,
Rene

@ehmicky
Copy link
Contributor

ehmicky commented Apr 27, 2020

Awesome!
I'll release this shortly :)

@ehmicky ehmicky merged commit 81af34a into netlify:master Apr 27, 2020
@ehmicky
Copy link
Contributor

ehmicky commented Apr 27, 2020

Released in 4.1.0 🎉

@rkretzschmar
Copy link
Contributor Author

Thank you very much @ehmicky !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants