Allow to specify server url without explicit port number

This commit is contained in:
Ivan Tivonenko
2015-08-21 05:28:22 +03:00
parent e3b688d1dd
commit 23653f67f0
3 changed files with 23 additions and 7 deletions

View File

@@ -49,6 +49,14 @@ function Server(remote, opts_) {
'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
// compatibility
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');
}
if (typeof opts.secure !== 'boolean') {
opts.secure = true;
}
this._remote = remote;
this._opts = opts;
this._ws = undefined;
@@ -126,7 +130,9 @@ function Server(remote, opts_) {
self._updateScore('ledgerclose', ledger);
});
/* eslint-disable no-unused-vars */
this.on('response_ping', function onPingResponse(message, request) {
/* eslint-enable no-unused-vars */
self._updateScore('response', request);
});