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

Commit aa21f48

Browse files
committed
add opts param to IpfsAPI, allow 'protocol' config
1 parent 7f93859 commit aa21f48

File tree

5 files changed

+845
-333
lines changed

5 files changed

+845
-333
lines changed

dist/ipfsapi.js

Lines changed: 810 additions & 312 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ipfsapi.min.js

Lines changed: 19 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exports = module.exports = () => {
77
'api-path': '/api/v0/',
88
'user-agent': `/node-$pkg.name}/${pkg.version}/`,
99
'host': 'localhost',
10-
'port': '5001'
10+
'port': '5001',
11+
'protocol': 'http'
1112
}
1213
}

src/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,31 @@ const Wreck = require('wreck')
77

88
exports = module.exports = IpfsAPI
99

10-
function IpfsAPI (host_or_multiaddr, port) {
10+
function IpfsAPI (host_or_multiaddr, port, opts) {
1111
const self = this
1212
const config = getConfig()
1313

1414
if (!(self instanceof IpfsAPI)) {
15-
return new IpfsAPI(host_or_multiaddr, port)
15+
return new IpfsAPI(host_or_multiaddr, port, opts)
1616
}
1717

1818
try {
1919
const maddr = multiaddr(host_or_multiaddr).nodeAddress()
2020
config.host = maddr.address
2121
config.port = maddr.port
2222
} catch (e) {
23-
config.host = host_or_multiaddr
24-
config.port = port || config.port
23+
if (typeof host_or_multiaddr === 'string') {
24+
config.host = host_or_multiaddr
25+
config.port = port && typeof port !== 'object' ? port : config.port
26+
}
27+
}
28+
29+
let lastIndex = arguments.length
30+
while (!opts && lastIndex-- > 0) {
31+
opts = arguments[lastIndex]
32+
if (opts) break
2533
}
34+
if (typeof opts === 'object') config.protocol = opts.protocol
2635

2736
// autoconfigure in browser
2837
if (!config.host &&

src/request-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function requestAPI (config, path, args, qs, files, buffer, cb) {
8787

8888
const opts = {
8989
method: files ? 'POST' : 'GET',
90-
uri: `http://${config.host}:${config.port}${config['api-path']}${path}?${Qs.stringify(qs, {arrayFormat: 'repeat'})}`,
90+
uri: `${config.protocol}://${config.host}:${config.port}${config['api-path']}${path}?${Qs.stringify(qs, {arrayFormat: 'repeat'})}`,
9191
headers: {}
9292
}
9393

0 commit comments

Comments
 (0)