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

Commit 62a539b

Browse files
committed
fix: Support api endpoint with no port defined
1 parent a869ae0 commit 62a539b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"detect-node": "^2.0.3",
3434
"flatmap": "0.0.3",
3535
"glob": "^7.1.2",
36+
"ip-regex": "^3.0.0",
3637
"ipfs-block": "~0.7.1",
3738
"ipfs-unixfs": "~0.1.14",
3839
"ipld-dag-cbor": "~0.12.0",

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const ipRegex = require('ip-regex')
34
const multiaddr = require('multiaddr')
45
const loadCommands = require('./utils/load-commands')
56
const getConfig = require('./utils/default-config')
@@ -15,7 +16,14 @@ function IpfsAPI (hostOrMultiaddr, port, opts) {
1516
} catch (e) {
1617
if (typeof hostOrMultiaddr === 'string') {
1718
config.host = hostOrMultiaddr
18-
config.port = port && typeof port !== 'object' ? port : config.port
19+
const addrParts = hostOrMultiaddr.split(':')
20+
21+
if (addrParts.length === 2 && ipRegex.v4({ exact: true }).test(addrParts[0]) &&
22+
(!port || typeof port === 'object')) {
23+
config.port = undefined
24+
} else {
25+
config.port = port
26+
}
1927
}
2028
}
2129

0 commit comments

Comments
 (0)