mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Allow to specify server url without explicit port number
This commit is contained in:
@@ -49,6 +49,14 @@ function Server(remote, opts_) {
|
|||||||
'Server host is malformed, use "host" and "port" server configuration');
|
'Server host is malformed, use "host" and "port" server configuration');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof opts.secure !== 'boolean') {
|
||||||
|
opts.secure = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Boolean(opts.port)) {
|
||||||
|
opts.port = opts.secure ? 443 : 80;
|
||||||
|
}
|
||||||
|
|
||||||
// We want to allow integer strings as valid port numbers for backward
|
// We want to allow integer strings as valid port numbers for backward
|
||||||
// compatibility
|
// compatibility
|
||||||
opts.port = Number(opts.port);
|
opts.port = Number(opts.port);
|
||||||
@@ -60,10 +68,6 @@ function Server(remote, opts_) {
|
|||||||
throw new TypeError('Server "port" must be an integer in range 1-65535');
|
throw new TypeError('Server "port" must be an integer in range 1-65535');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof opts.secure !== 'boolean') {
|
|
||||||
opts.secure = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._remote = remote;
|
this._remote = remote;
|
||||||
this._opts = opts;
|
this._opts = opts;
|
||||||
this._ws = undefined;
|
this._ws = undefined;
|
||||||
@@ -126,7 +130,9 @@ function Server(remote, opts_) {
|
|||||||
self._updateScore('ledgerclose', ledger);
|
self._updateScore('ledgerclose', ledger);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
this.on('response_ping', function onPingResponse(message, request) {
|
this.on('response_ping', function onPingResponse(message, request) {
|
||||||
|
/* eslint-enable no-unused-vars */
|
||||||
self._updateScore('response', request);
|
self._updateScore('response', request);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -818,4 +818,9 @@ describe('RippleAPI - offline', function() {
|
|||||||
assert(!api.isValidAddress(hex));
|
assert(!api.isValidAddress(hex));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
|
it('RippleAPI - implicit server port', function() {
|
||||||
|
const api = new RippleAPI({servers: ['wss://s1.ripple.com']});
|
||||||
|
});
|
||||||
|
/* eslint-enable no-unused-vars */
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ describe('Remote', function() {
|
|||||||
assert.throws(
|
assert.throws(
|
||||||
function() {
|
function() {
|
||||||
new Remote({
|
new Remote({
|
||||||
servers: [{host: 's-west.ripple.com', port: null, secure: true}]
|
servers: [{host: 's-west.ripple.com', port: 'null', secure: true}]
|
||||||
});
|
});
|
||||||
}, TypeError);
|
}, TypeError);
|
||||||
});
|
});
|
||||||
@@ -148,21 +148,26 @@ describe('Remote', function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
"url" module used in server parses such urls with error, it return
|
||||||
|
null for port, so in this case default port will be used
|
||||||
|
|
||||||
it('Server initialization -- url string -- invalid port', function() {
|
it('Server initialization -- url string -- invalid port', function() {
|
||||||
assert.throws(
|
assert.throws(
|
||||||
function() {
|
function() {
|
||||||
new Remote({
|
new Remote({
|
||||||
servers: ['ws://s-west.ripple.com:null']
|
servers: ['ws://s-west.ripple.com:invalid']
|
||||||
});
|
});
|
||||||
}, Error
|
}, Error
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
it('Server initialization -- url string -- port out of range', function() {
|
it('Server initialization -- url string -- port out of range', function() {
|
||||||
assert.throws(
|
assert.throws(
|
||||||
function() {
|
function() {
|
||||||
new Remote({
|
new Remote({
|
||||||
servers: ['ws://s-west.ripple.com:65537:']
|
servers: ['ws://s-west.ripple.com:65537']
|
||||||
});
|
});
|
||||||
}, Error
|
}, Error
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user