Hi, I’m trying to access my ipfs node (created with js-ipfs in nodejs) over http API (in the aim of using js-ipfs-cluster), but everytime I tried I got a connection refused error .
node : 12.9.1.
Js-ipfs version : 0.50.2.
After reading some post about it I tried to allow CORS request but nothing changed.
const ipfsNode = await IPFS.create({
repo: './jsipfs',
config: {
Addresses: {
Swarm: [
'/ip4/0.0.0.0/tcp/4012',
'/ip4/127.0.0.1/tcp/4013/ws'
],
API: '/ip4/127.0.0.1/tcp/5001',
Gateway: '/ip4/127.0.0.1/tcp/9191'
}
}
})
const key1 = 'API.HTTPHeaders.Access-Control-Allow-Origin'
const val1 = ['*']
ipfsNode.config.set(key1, val1)
const key2 = 'API.HTTPHeaders.Access-Control-Allow-Methods'
const val2 = ["PUT", "POST", "GET"]
ipfsNode.config.set(key2, val2)
I’m using postman to do the http request (which works well if a download ipfs cli for windows).
Any idea about what should I do to make it work ?
wclayf
October 26, 2020, 5:18pm
2
Connection Refused error normally means the port you think is open isn’t even listening, or the url has a typo or something like that, and isn’t an indication that some code tried to do something and failed.
The url works well, If I launch ipfs with the CLI and change the port it works. I got a response.
I use this url : http://127.0.0.1:5001/api/v0/swarm/peers (request type : POST)
So if the port is not open or not listening, it means perhaps something is missing in my node project ?
I just created and init a new emtpy node project and added js-ipfs by doing :
yarn add ipfs
Do I need to add others packages ?
wclayf
October 26, 2020, 9:54pm
4
This kinda thing might help you check addresses,
const ipfsNode = await IPFS.create();
const addresses = await ipfsNode.swarm.localAddrs();
console.log(addresses);
but I’ve never done what you’re doing so hopefully someone else can help.
Thansk for the advice, It seems I can only see swarm addresses :
(Which seems to be normal because I called swarm.localAddrs() )
[
<Multiaddr 04ac119001060fa2 - /ip4/172.17.144.1/tcp/4002>,
<Multiaddr 04194f0c9e060fa2 - /ip4/25.79.12.158/tcp/4002>,
<Multiaddr 04c0a80114060fa2 - /ip4/192.168.1.20/tcp/4002>,
<Multiaddr 047f000001060fa2 - /ip4/127.0.0.1/tcp/4002>,
<Multiaddr 047f000001060fa3dd03 - /ip4/127.0.0.1/tcp/4003/ws>
]