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

feat(createNodeHttpRequester): Add proxy support to another Agent on createNodeHttpRequester #1180

Merged
merged 8 commits into from
Aug 5, 2020

Conversation

diogolmenezes
Copy link

Hey guys, today i needed call Algolia behind my entherprise proxy server.

I did not found no way to do this with this lib so I added to the createNodeHttpRequester this feature.

To use it, you need to pass the proxy url to requester option.

https://www.algolia.com/doc/api-client/advanced/configure-the-client/javascript/?language=javascript#requester

like this:

const algoliasearch = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey',
{
requester: createNodeHttpRequester('http://yourproxy:8080')
},
);

@diogolmenezes diogolmenezes changed the title Adding support do proxy feat(createNodeHttpRequester): Add proxy support to createNodeHttpRequester Jul 29, 2020
@Haroenv
Copy link
Contributor

Haroenv commented Jul 30, 2020

This makes sense, however this would make that package a a dependency, alternatively you could make the whole agent an argument, so you can choose the version, as well as choosing a different agent. What do you think?

@diogolmenezes
Copy link
Author

This makes sense, however this would make that package a a dependency, alternatively you could make the whole agent an argument, so you can choose the version, as well as choosing a different agent. What do you think?

Nice, i will do it !

@diogolmenezes diogolmenezes changed the title feat(createNodeHttpRequester): Add proxy support to createNodeHttpRequester feat(createNodeHttpRequester): Add proxy support to another Agent on createNodeHttpRequester Aug 4, 2020
@diogolmenezes
Copy link
Author

diogolmenezes commented Aug 4, 2020

This makes sense, however this would make that package a a dependency, alternatively you could make the whole agent an argument, so you can choose the version, as well as choosing a different agent. What do you think?

Done. Now to use it, you have to :

const agent = new HttpsProxyAgent(process.env.http_proxy);
const algoliasearch = algoliasearch(
'YourApplicationID',
'YourSearchOnlyAPIKey',
{
requester: createNodeHttpRequester(agent)
}
)

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

it's not straightforward to test this, since the agent only gets called by http or https, so it's ok to leave this as-is for me

@Haroenv Haroenv merged commit 3818322 into algolia:master Aug 5, 2020
Haroenv added a commit to algolia/gatsby-plugin-algolia that referenced this pull request Dec 14, 2021
* feat(config): Add requester param to pass it to algoliasearch to use a corporate proxy

We're using a corporate proxy and cannot make `gatsby-plugin-algolia` work without passing a custom requester.

I found this PR (algolia/algoliasearch-client-javascript#1180) where `createNodeHttpRequester` was extended to pass a custom HTTP agent.
With this change you can pass a custom requester to `gatsby-plugin-algolia` which resolved our issue.

* feat(config): Add param to set the algoliasearch options

* docs(readme): include algoliasearchOptions

Co-authored-by: Haroen Viaene <hello@haroen.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants