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

Unable to make request to raw IP address (Error: connect ECONNREFUSED) #4877

Closed
Bilal-Z opened this issue Jul 23, 2022 · 1 comment
Closed

Comments

@Bilal-Z
Copy link

Bilal-Z commented Jul 23, 2022

Describe the issue

I am trying to make a request to a 3rd party SOAP API, provided an IP address http://XXX.XXX.XXX.XXX:40871

I get the following error:

{
    "success": false,
    "error": "connect ECONNREFUSED XXX.XXX.XXX.XXX:40871",
    "trace": "Error: connect ECONNREFUSED XXX.XXX.XXX.XXX:40871\n    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)"
}

while testing locally I edited my hosts file and provided a host name to the IP

XXX.XXX.XXX.XXX my-host-name.com

then made a request to http://my-host-name.com:40871 and successfully got a response.

I can not do this in production since we are using heroku to deploy our app

Code

Our app is a middleware to make requests to the 3rd party API since they requires a static IP in its whitelist. we create a axios instance and recieve further options in the request body.

const agent = new HttpsProxyAgent(process.env.STATIC_URL!);
	const baseOptions: AxiosRequestConfig = {
		proxy: false,
		httpsAgent: agent,
	};
	const instance = axios.create(baseOptions);
	const response = await instance(req.body);

	res.send({ success: true, response: response.data });

here is the request body:

{
    "method": "POST",
    "baseURL": "http://XXX.XXX.XXX.XXX:40871",
    "url": "/IDORequestService/IDOWebService.asmx",
    "data": {{xmlBody}},
    "headers": {
      "Content-type": "text/xml",
      "SOAPAction": "http://frontstep.com/IDOWebService/CreateSessionToken",
      "Accept": "*/*",
      "Accept-Encoding": "gzip, deflate, br",
      "Connection": "keep-alive"
  }
}

Expected behavior

it should work with IP addresses

Environment

  • Axios v0.27.2
  • Node.js v16.16.0
  • OS: Windows 11/Linux Mint 19.3
  • Additional Library Versions: https-proxy-agent: v5.0.1
@Bilal-Z
Copy link
Author

Bilal-Z commented Jul 26, 2022

The problem was I did not have an httpAgent so it was not using the proxy for http requests, which is why the API server was probably refusing connection. Since it has the static IP in its whitelist and not our server IP.

const agent = new HttpsProxyAgent(process.env.STATIC_URL!);
const baseOptions: AxiosRequestConfig = {
    proxy: false,
    httpsAgent: agent,
    httpAgent: agent,
};
const instance = axios.create(baseOptions);
const response = await instance(req.body);

res.send({ success: true, response: response.data });

adding the httpAgent fixed the issue.

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

No branches or pull requests

1 participant