IPFS API returns 404

Hello everyone!

I’m writing a POC which runs an IPFS node and also an instance of IPFS Cluster. I can successfully start the node and the cluster. The problem is that the IPFS API only returns 404 RPC endpoint doesn’t exist. I used the functions serveHTTPApi and serveHTTPGateway from the daemon source code. Both the API and Gateway starts up, it’s possible to see it in the open ports of my pc

main 14281 mypc 24u IPv4 0x9192403e3001e1dd 0t0 TCP *:4001 (LISTEN)
main 14281 mypc 26u IPv6 0x9192403e2ee8bd3d 0t0 TCP *:4001 (LISTEN)
main 14281 mypc 43u IPv4 0x9192403e2e8e856d 0t0 TCP localhost:5001 (LISTEN)
main 14281 mypc 45u IPv4 0x9192403e2ec91655 0t0 TCP localhost:8080 (LISTEN)

IPFS node is running API server listening on /ip4/127.0.0.1/tcp/5001 WebUI: http://127.0.0.1:5001/webui Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080

I’m also able to access the WebUI but with the message Failed to connect to the API. Using curl returns 404 no any endpoint too.

The cluster throws this errors:

2020-06-26T20:30:19.908+0100 ERROR ipfshttp IPFS request unsuccessful (repo/stat?size-only=true). Code 404. Body: 404 page not found

2020-06-26T20:30:19.908+0100 ERROR p2p-gorpc IPFS request unsuccessful (repo/stat?size-only=true). Code 404. Body: 404 page not found

2020-06-26T20:30:19.908+0100 ERROR diskinfo IPFS request unsuccessful (repo/stat?size-only=true). Code 404. Body: 404 page not found

Things I already tried:
What says in WebUI to add to the HTTPHeaders “Access-Control-Allow-Methods” and “Access-Control-Allow-Origin”
Set Gateway.Writable: true
https://discuss.ipfs.io/t/ipfs-gateway-returns-404-when-using-api-v0-add/6795/2

Bare in mind that if I start the ipfs via ipfs daemon my cluster can easily connect to it. So it’s only a problem in my own ipfs node.

If someone already suffered from this or can give a hint about what might be the problem I would really appreciate. Thank you!

Package versions:
github.com/ipfs/go-ipfs v0.5.0
github.com/ipfs/go-ipfs-config v0.5.3
github.com/ipfs/ipfs-cluster v0.13.0

Do you mean you are running a custom build of the ipfs daemon?

Sorry for the late response toke the weekend off.

Yes I’m using the go-ipfs library to initialize my own node based on this example and a custom build of the ipfs-cluster in the same code. Basically I first start the IPFS node and then if succeed starts the ipfs cluster and connects to 127.0.0.1:5001.
To initialize the IPFS node API I toke a look at the IPFS daemon source code and used both the serveHTTPApi and serveHTTPGateway functions to expose the API and Gateway Ports. But I guess I might be missing something because indeed the ports were open, but the API does not expose any endpoint.

Well, your API 404-ing means request handlers might be missing. I am not sure what needs to be done to run the gateway by hand (doesn’t the example does it by itself?). If you are binding both ipfs and ipfs-cluster in a single binary, you could skip using the http api altogether though and add a new connector implementation directly that uses the ipfs core API directly (related https://github.com/textileio/go-textile/pull/831/files#diff-5d87e68af33532d3c963b1dc695da064R1)

I ran the example code and saw that it only opened the port 4001 but not the API (5001) and Gateway (8080) ones so I guess not.

That might be really handy! Tomorrow I will give it a try and will leave feedback when done. Thank you a lot

@hector Just managed to make it work with a new connector. Only needed to rewrite a little bit of the code of the Textile PR you sended. Thank you a lot

1 Like