When I start my local ipfs node with “ipfs daemon”, in the cmd I get this:
With this, I can say 127.0.0.1:8080/ipfs/CID and read files from IPFS.
In my Node.js app, when I run ipfs.create(), In the console I get something like this:
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/...
Swarm listening on /ip4/192.168.0.5/tcp/4002/p2p/...
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/...
These are not readonly gateways. Does js-ipfs have a readonly gateway server? If yes, what is the readonly gateway in js-ipfs, or how can I find it? Or how can I configure it to be on whatever port I want?
I have found that the create() has config → Addresses → Gateway option, with the default on /ip4/127.0.0.1/tcp/9090
But while my app is running, if I try to read a file with 127.0.0.1:9090/ipfs/CID, it doesn’t work, I get ERR_CONNECTION_REFUSED
I have found the answer. Yes, js-ipfs has a readonly gateway server, but it’s not starting implicitly togheter with the node, you have to use ipfs-http-gateway package. The package doesn’t really have good instructions, but here is how you do it. You import HttpGateway class from the package and give your ipfs instance to it as a constructor, then you call .start() from the HttpGateway instance. The .start() will take the config options from your ipfs instance, and will search for Adresses → Gateway options that defaults to /ip4/127.0.0.1/tcp/9090 and start the gateway to that port. You can read the code from the package where the HttpGateway class is written, and you’ll figure it all out.