1

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?

3
  • Please, be specific and explain your case in details, whether it's possible totally depends on it. What module? Is it public and can be linked? Without any other info, all I could say if if you can import the same axios module copy as another module uses, you can change axios.defaults. And if you can't import it because of how your app is organized, you're out of luck Commented Jan 8 at 21:38
  • Thank you for answering me, I tried to add more context and details. Please tell me if things are not clear or if you need more info Commented Jan 8 at 22:21
  • I tried, as you propose, to import the axios module of the DyDx module with import axios, { Axios, AxiosProxyConfig } from '@dydxprotocol/v4-client-js/node_modules/axios'; And then add my proxy parameters in axios.defaults but I don't know why it doesn't work. Commented Jan 9 at 10:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This looks promising but I am still stuck. This time I simplified my code to the maximum: import axios from 'axios'; axios.get('https://indexer.v4testnet.dydx.exchange/v4/time'); If I do not add the proxy data I get ENOTFOUND getaddrinfo and I if I add the proxy I am back to the error 500 handshake failed. I also tried with other public API and I get the same result. Looks like Axios has no way to access distant resource.
@Upbeat The problem with a proxy itself differs from the original one. If you have the same with other urls, this is likely specific to how axios works with proxies in general. I didn't check this, but it the implementation looks like "proxy" option isn't supposed to do anything useful. Try to do this the way it's done in node in general, i.e though http/https agent stackoverflow.com/a/78781719/3731501 or stackoverflow.com/questions/18586902/…
It works like a charm, thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.