diff --git a/util/fix-connections.js b/util/fix-connections.js index 26bf0e2..01f1d3d 100644 --- a/util/fix-connections.js +++ b/util/fix-connections.js @@ -1,6 +1,3 @@ -var getNet = require('./get-net') -var getWS = require('./get-ws') - // *** BACKSTORY *** // there has been an evolution of how connection host:port and ws are set // historically you have been able to set host, port net connections, @@ -13,8 +10,8 @@ var getWS = require('./get-ws') // - writes host,port,ws settings based on the connections.incoming setting module.exports = function fixConnections (config) { - const net = getNet(config) - const ws = getWS(config) + const net = getTransport(config, 'net', 8008) + const ws = getTransport(config, 'ws', 8989) var errors = [] if (config.host && net.host) { @@ -35,3 +32,29 @@ module.exports = function fixConnections (config) { return config } + +var get = require('lodash.get') + +function getTransport (config, protocolName, defaultPort) { + var connection = get(config, 'connections.incoming.'+protocolName, []) + .find(function (transport) { + return isAccessible(transport) + }) + + if (!connection) return { host: undefined, port: defaultPort } + + return { + host: connection.host, + port: connection.port || defaultPort + } +} + +function isAccessible (transport) { + return transport.scope === 'private' || transport.scope.includes('private') || + transport.scope === 'local' || transport.scope.includes('local') || + transport.scope === 'public' || transport.scope.includes('public') +} + + + + diff --git a/util/get-net.js b/util/get-net.js deleted file mode 100644 index bf6bca4..0000000 --- a/util/get-net.js +++ /dev/null @@ -1,20 +0,0 @@ -var get = require('lodash.get') - -module.exports = function getNet (config) { - var connection = get(config, 'connections.incoming.net', []) - .find(function (transport) { - return isAccessible(transport) - }) - - if (!connection) return { host: undefined, port: 8008 } - - return { - host: connection.host, - port: connection.port || 8008 - } -} - -function isAccessible (transport) { - return transport.scope === 'private' || transport.scope.includes('private') || - transport.scope === 'public' || transport.scope.includes('public') -} diff --git a/util/get-ws.js b/util/get-ws.js deleted file mode 100644 index ad8a2a0..0000000 --- a/util/get-ws.js +++ /dev/null @@ -1,20 +0,0 @@ -var get = require('lodash.get') - -module.exports = function getNet (config) { - var connection = get(config, 'connections.incoming.ws', []) - .find(function (transport) { - return isAccessible(transport) - }) - - if (!connection) return {host: undefined, port: 8989} - - return { - host: connection.host, - port: connection.port || 8989 - } -} - -function isAccessible (transport) { - return transport.scope === 'private' || transport.scope.includes('private') || - transport.scope === 'public' || transport.scope.includes('public') -}