I'm building a typescript app that relies on DyDx v4-client as a Node module 1 that itself relies on Axios to make HTTP requests.
I'm behind a corporate proxy and Axios cannot make any requests.
For example, when trying to GET https://indexer.v4testnet.dydx.exchange/v4/time the output is Error: getaddrinfo ENOTFOUND
. But it works from a web browser so I know it's not blocked by the corporate firewall.
Since Axios is kind of "buried" as a module of DyDx (which is itself a module) I don't have direct explicit access to it in my code. So I tried to directly modify the request
function in the compiled JS file to manually add my proxy parameters:
function request(url, method, body, headers) {
return axiosRequest({
url,
method,
data: body,
headers,
proxy: {
protocol: 'http',
host: 'foo.bar',
port: 1234
}
});
Doing this Axios throws me the following error as an HTML page. This page is generated by the firewall. It's like the firewall interpreted the Axios call as a browser call...
Handshake failed
The SSL handshake could not be performed.
Host: service.iwanttoaccess.com
Reason: Can't initialize server context:handshakefailed:server state 1:state 9:Application response 500 handshakefailed
How do I properly set my proxy parameters when I don't have direct access to Axios?
The library encapsulates Axios instance which it uses in axiosRequest
and doesn't expose it. This is generally a bad design because it can cause problems like this one exactly.
A way to fix this in this case is to force the library to use the same Axios instance as the project by overriding it in package.json:
"dependencies": {
"axios": "1"
},
"overrides": {
"@dydxprotocol/v4-client-js": {
"axios": "$axios"
}
}
Then global Axios config can be modified by importing axios
and changing axios.defaults
.
The library uses a specific Axios version that may be incompatible with the version that is used in the project. In case this is the case, multiple versions can be installed simultaneously, so the version that the library uses could be imported in the project under a different name than the regular one.