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

Commit

Permalink
feat: return protocol from getEndpointConfig (#935)
Browse files Browse the repository at this point in the history
The protocol is used to construct the request, and it's useful to
be able to check it has been set correctly, so we add it here to
he the util.getEndpointConfig() return value.

License: MIT
Signed-off-by: Oli Evans <oli@tableflip.io>
  • Loading branch information
olizilla authored and Alan Shaw committed Jan 28, 2019
1 parent af6ba05 commit 12ddaa3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ Complete documentation for these methods is coming with: https://github.com/ipfs

> `ipfs.util.getEndpointConfig()`
This returns an object containing the `host` and the `port`
This returns an object containing the `host`, `port` and `protocol`

##### Get libp2p crypto primitives

Expand Down
4 changes: 3 additions & 1 deletion src/util/get-endpoint-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module.exports = (config) => {
return () => ({
host: config.host,
port: config.port
port: config.port,
protocol: config.protocol,
'api-path': config['api-path']
})
}
7 changes: 5 additions & 2 deletions test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ describe('.util', () => {
})

describe('.getEndpointConfig', () => {
it('should return the endpoint configured host and port', function () {
it('should return the endpoint configuration', function () {
const endpoint = ipfs.util.getEndpointConfig()

expect(endpoint).to.have.property('host')
expect(endpoint.host).to.equal('127.0.0.1')
expect(endpoint.protocol).to.equal('http')
expect(endpoint['api-path']).to.equal('/api/v0/')
// changes per test run so we just assert it exists.
expect(endpoint).to.have.property('port')
})
})
Expand Down

0 comments on commit 12ddaa3

Please sign in to comment.