Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bcc391b

Browse files
committedAug 27, 2015
autoconfigure host/port in browser
1 parent f14c12f commit bcc391b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
 

‎index.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@ module.exports = function (host_or_multiaddr, port) {
2828
host = host_or_multiaddr
2929
}
3030

31-
if (!host) host = 'localhost'
32-
if (!port) port = 5001
31+
if (!host) {
32+
if (window && window.location) {
33+
// autoconfigure in browser
34+
var split = window.location.host.split(':')
35+
this.host = split[0]
36+
this.port = split[1] || 80
37+
} else {
38+
// default api
39+
host = 'localhost'
40+
port = 5001
41+
}
42+
}
3343

3444
function send (path, args, opts, files, buffer, cb) {
3545
var query, stream, contentType

0 commit comments

Comments
 (0)
This repository has been archived.