Open fahadsubzwari924 opened 3 years ago
The README shows how to override the fetch method:
// Set specific http request headers:
const nodeFetch = require('node-fetch');
const geocoder = NodeGeocoder({
provider: 'google',
fetch: function fetch(url, options) {
return nodeFetch(url, {
...options,
headers: {
'user-agent': 'My application <email@domain.com>',
'X-Specific-Header': 'Specific value'
}
});
}
});
In there you can add any options you want, including theoretically overriding the agent using something like the http-proxy-agent
module:
const nodeFetch = require('node-fetch');
const HttpProxyAgent = require('http-proxy-agent');
const options = {
provider: 'openstreetmap',
fetch: function (url, options) {
// Configure to use the proxy from HTTP_PROXY or http_proxy env variable
let proxy = process.env.http_proxy || process.env.HTTP_PROXY;
if (proxy) {
options.agent = new HttpProxyAgent(proxy);
}
return nodeFetch(url, {
...options,
});
},
};
Also note that node-geocoder uses node-fetch version 2, and you will need to use v2 as well in the above example. I have tried using it with node-fetch v3 but it had problems (caused my unit tests to hang indefinitely, not sure what the underlying issue actually was). I will open an issue about it and if possible will create a PR to upgrade to node-fetch v3.
I have my
node.js
server running on avm
along with aproxy
on it. Now i am usingnode-geocode
r to getlat
lng
fromnode-geocoder
like thisnow it's throwing an error due to proxy like this
So how can i pass my
proxy
settings innode-geocoder
?