Michael S. Scherotter
Michael S. Scherotter

Reputation: 10785

Unable to call http://localhost Azure Function from https://localhost node app

I have one Node.js Azure function running on a Windows 11 system at http://localhost:7071/api/FunctionName.

I can execute the function by calling it from a browser window no problem.

Now when I call it from another node app running on localhost with axios or fetch, I get an ECONNREFUSED error.

I get the same results whether I'm running from NPM start or inside VS Code. It works fine on one system.

Any suggestions? - this used to work no problem.

Thanks.

Upvotes: 4

Views: 2591

Answers (2)

mehdi Ichkarrane
mehdi Ichkarrane

Reputation: 426

there has been a breaking change on dns resolution for localhost since node 17.

Your solution works fine because providing the Ip explicitly prevents the dns resolution mechanism.

other possible solutions:

1- force the node app to use ipv4 first:

const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');

2 - downgrade node to version 16

this issue is also reported on github: #40702

Upvotes: 2

Michael S. Scherotter
Michael S. Scherotter

Reputation: 10785

I just figured out a fix - calling the localhost IP address directly works: http://127.0.0.1/api/FunctionName.

Now I need to figure out what caused the configuration change.

Upvotes: 5

Related Questions