Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

ipfs behind proxy #581

Closed
sjeeva opened this issue Aug 4, 2017 · 10 comments
Closed

ipfs behind proxy #581

sjeeva opened this issue Aug 4, 2017 · 10 comments

Comments

@sjeeva
Copy link

sjeeva commented Aug 4, 2017

I am running my IPFS behind an ngnix proxy and redirected port 5001 of IPFS to http://<IPAddress>/ipfs

We are developing a Web Interface from which we want to access http://<IPAddress>/ipfs, however js-ipfs-api supports ipfsAPI which seems to be accepting only IP address / port as shown below
var ipfs = ipfsAPI('ip4/<IPAddress>/tcp/5001', {protocol: 'http'})

Is there any option that would allow me to connect to http://<IPAddress>/ipfs using ipfsAPI?

@daviddias
Copy link
Contributor

Hi @sjeeva, I'm not sure if I understand your question, but let me try to answer it and you tell me what I missed.

When you create an ipfsAPi instance with /ip4/<some-ip-addr>/tcp/5001, you are using the multiaddr format, which translates to http://:5001.

Does this answer your question? What is the http:///ipfs (triple /) that you are describing?

@sjeeva
Copy link
Author

sjeeva commented Aug 5, 2017

Opps!! few details where missing due to github formatting...

How do we translate http://<IPAddr>:<Port>/path/subpath in multiaddr format

@dryajov
Copy link
Contributor

dryajov commented Aug 5, 2017

@sjeeva should be /ip4/<IPAddress>/tcp/5001/http or /ip4/<IPAddress>/tcp/5001/https same for websockets (ws/wss).

@daviddias
Copy link
Contributor

@sjeeva I see, you want to hit a path so that it gets routed in nginx. http paths are not part of the multiaddr spec (although it has been considered).

Wanna add support for that specific feature to this module?

@sjeeva
Copy link
Author

sjeeva commented Aug 5, 2017

@diasdavid, yes.. if you give me a few pointer in the code, I can work on this feature...

@daviddias
Copy link
Contributor

daviddias commented Aug 5, 2017

The parsing happens here -- https://github.com/ipfs/js-ipfs-api/blob/master/src/index.js#L9-L44 --, you should just have to test for the multiaddr + path case and break it to host (including path) + port respectively.

@vasco-santos
Copy link
Contributor

vasco-santos commented Apr 10, 2018

Hey @diasdavid and @sjeeva

I have deployed IPFS behind a proxy and I have analyzed this problem.

Basically, the problem is in this line. There is a default port defined by getConfig. As a consequence, when ipfsAPI receives a http://<IPAddress>/ipfs, the default port is appended to it: http://<IPAddress>/ipfs:5001.

I agree that we should have a default port value, but it blocks this use cases. I was thinking on a possible solution for identifying when we should set the default port.

try {
    const maddr = multiaddr(hostOrMultiaddr).nodeAddress()
    config.host = maddr.address
    config.port = maddr.port
  } catch (e) {
    if (typeof hostOrMultiaddr === 'string') {
      config.host = hostOrMultiaddr
      config.port = port && typeof port !== 'object' ? port : config.port
    }
  }

If the received parameter is not in the multiaddr format, the catch code will be executed. Here, we have to decide wether to use the default port or not.

I cannot find any good solution for solving this maintaining the default value, when the received hostname is not a multiaddr but it is a String. In this case, I think I would go with the following:

  } catch (e) {
    if (typeof hostOrMultiaddr === 'string') {
      config.host = hostOrMultiaddr
      if (hostOrMultiaddr.indexOf(':') > -1 || !port || typeof port === 'object' ) ){
        config.port = undefined
      } else {
        config.port = port
      }
    }
  }

What are your thoughts? Should I advance with this solution?

@victorb
Copy link
Contributor

victorb commented Apr 18, 2018

There seems to be two issues here. First is how js-ipfs-api handles traditional strings, those are fine to fix for now (I have no opinion on the specific implementation). But the general plan is to move everything to multiaddrs, which means we should also be able to support paths in /http. This has yet to been defined in multiaddr, so I opened this issue about it: multiformats/multiaddr#63

The question How do we translate http://<IPAddr>:<Port>/path/subpath in multiaddr format has the theoretical answer of /ip4/1.2.3.4/tcp/5001/http/path/subpath but as this has yet to been defined, we should wait for multiformats/multiaddr#63 to finalize before going that route.

@vasco-santos
Copy link
Contributor

Thanks for your analyze @victorbjelkholm

Regarding the multiaddr I agree with you, it should definitely support what you described in multiformats/multiaddr#63. I will subscribe this issue as well, in order to help in its advances.

For the js-ipfs-api multiaddr error fallback, since you do not have any particular opinion, I will remove the default port by now, and create a PR. Then, I will wait for further opinions.

@alanshaw
Copy link
Contributor

@sjeeva you can use api-path and initialise your API like this:

const IpfsApi = require('ipfs-api')
const ipfs = IpfsApi({
  protocol: 'http',
  host: '<IPAddress>',
  port: 80,
  'api-path': '/ipfs/api/v0'
})

Let me know if you have any other probs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants