Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy support for amp-optimizer #857

Merged
merged 5 commits into from
Jul 30, 2020
Merged

Conversation

todoa2c
Copy link
Contributor

@todoa2c todoa2c commented Jul 8, 2020

Proxy support using node-fetch-with-proxy instead of node-fetch.
If you need to use proxy, just set the environment variable https_proxy.

Thanks.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@todoa2c
Copy link
Contributor Author

todoa2c commented Jul 8, 2020

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@sebastianbenz
Copy link
Collaborator

Thanks for creating this! One suggestion: as the code for integrating this is trivial, would you mind implementing this directly instead of adding an additional dependency?

@todoa2c
Copy link
Contributor Author

todoa2c commented Jul 13, 2020

@sebastianbenz I searched for this fix that doesn't require any additional libraries.
But that seemed difficult.
If I use node-fetch, you need an agent like HttpProxyAgent, which is also an additional library.
Is there any idea to implement node-fetch agent without using it, implementation without node-fetch, or any other method?

@sebastianbenz
Copy link
Collaborator

Sorry for not being more clear. Integrating https://www.npmjs.com/package/http-proxy-agent is fine as it seems to be the "standard" node way of integrating of proxy. What I'd like to avoid is integrating node-fetch-with-proxy as it's a super thin wrapper with only a few LOC and super low usage.

When environment variable name https_proxy is available,
HttpsProxyAgent is used as node-fetch agent.
@todoa2c
Copy link
Contributor Author

todoa2c commented Jul 15, 2020

@sebastianbenz Sorry for late reaction.
This time https-proxy-agent matches so I added and fixed code.

Copy link
Collaborator

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! This looks good! One request: can you also add this here https://github.com/ampproject/amp-toolbox/blob/main/packages/optimizer/lib/DomTransformer.js#L156 to enable proxy support at runtime.

@todoa2c
Copy link
Contributor Author

todoa2c commented Jul 23, 2020

@sebastianbenz I checked cross-fetch library but it doesn't support agent like node-fetch.

Should I replace cross-fetch to node-fetch? or any ideas?

@sebastianbenz
Copy link
Collaborator

Hm - that's annoying. I think it's fine to replace cross-fetch in that case and we don't release a browser bundle yet which would benefit from cross fetch.

@todoa2c
Copy link
Contributor Author

todoa2c commented Jul 28, 2020

@sebastianbenz Ok, so let's try replacing "cross-fetch" with "node-fetch" once in a separate branch.
Is it possible to merge this pull request? I'm using next.js now, but I'm having trouble with next.js because it relies on amp-toolbox and I'm having to wait a huge amount of time for postinstall in a proxy environment.

@sebastianbenz sebastianbenz merged commit e912d50 into ampproject:main Jul 30, 2020
tharders pushed a commit that referenced this pull request Aug 17, 2020
* Proxy support for amp-optimizer

* Environment variable https_proxy support

* Revert "Proxy support for amp-optimizer"

This reverts commit 8e129fc.

* Use https-proxy-agent.

When environment variable name https_proxy is available,
HttpsProxyAgent is used as node-fetch agent.

Co-authored-by: Sebastian Benz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants