Reputation: 55
I'm trying to access a strapi api in my local dev environement. Wheras I have no issues to access the api under the same url with postman, trying to access it from my node server i run into this error:
connect ECONNREFUSED ::1:1337
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 1337
This is the part of my server where I make the request:
const request = require('request');
request({
url: 'http://localhost:1337/api/homepage?populate=*',
headers: {
'Authorization': 'Bearer 123455347' },
rejectUnauthorized: false
}, function(err, res) {
if(err) {
console.error(err);
} else {
console.log(res.body);
}
});
}
Why refuses strapi the connection? I'm helpless.. Ist there something I missed while configuring it?
Upvotes: 1
Views: 1203
Reputation: 344
I had the exact same issue and I have found a work around inspired by a discussion on GitHub (https://github.com/axios/axios/issues/3821).
The problem seems to be that Strapi does not support IPv6 properly with all Node-Versions (https://github.com/strapi/strapi/issues/12285).
When I try to access my Strapi-API with the address http://localhost:1337 my computer resolves the IPv6 address ::1: and this causes the beforehand mentioned error.
connect ECONNREFUSED ::1:1337
Therefore instead of trying to connect to http://localhost:1337 try to use the IPv4 address of your computer. In my case this meant to connect to http://192.168.0.12:1137.
Upvotes: 3