Search code examples
network-programminglannasipfs

IPFS running on NAS, cannot connect to API / Gateway from networked machine


I have IPFS daemon running on my NAS, pinning some files. I have the following config:

{
  "API": {
    "HTTPHeaders": {}
  },
  "Addresses": {
    "API": "/ip4/0.0.0.0/tcp/6001",
    "Announce": [],
    "Gateway": "/ip4/0.0.0.0/tcp/8080",
    "NoAnnounce": [],
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001",
      "/ip4/0.0.0.0/udp/4001/quic",
      "/ip6/::/udp/4001/quic"
    ]
  },
  "AutoNAT": {},

  },

...

  "Gateway": {
    "APICommands": [],
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "X-Requested-With",
        "Range",
        "User-Agent",
        "Access-Control-Expose-Headers"
      ],
      "Access-Control-Allow-Methods": [
        "GET", "POST"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ],
         "X-Special-Header": [       "Access-Control-Expose-Headers: Ipfs-Hash"    ]
    },
    "NoDNSLink": false,
    "NoFetch": false,
    "PathPrefixes": [],
    "PublicGateways": null,
    "RootRedirect": "",
    "Writable": true
  },



I changed the port from 5001 to 6001 because the NAS is running Nginx and serving its web UI on 5001.

My companion and desktop on another machine on the network are unable to access the API and can't seem to connect to the node, despite the node working fine (direct access to pinned files works).

Which settings do I need to change to allow connecting to the node from network devices?


Solution

  • The configuration is missing the CORS permission in its API section:

    {
      "API": {
        "HTTPHeaders": {
          "Access-Control-Allow-Origin": ["*"]
        }
      },
    
    ...
    

    Originally answered by Hector here: https://discuss.ipfs.io/t/network-access-to-api/9742/5