Skip to content

Commit 445d52e

Browse files
committed
Better handling of hostname/ip:port format
1 parent 6f4fb16 commit 445d52e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/ConnectionPool.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,14 @@ class ConnectionPool {
336336
// if we encounter the second case, we should
337337
// use the hostname instead of the ip
338338
var address = node.http.publish_address
339-
const hostAndIpRegex = /^[a-z0-9_.-]*\/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/gi
340-
const match = address.match(hostAndIpRegex)
341-
if (match !== null) {
342-
const ipRegex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/
343-
const ip = address.match(ipRegex)[0]
344-
// extract the hostname, the -1 at the end removes the final /
345-
const hostname = address.slice(0, address.indexOf(ip) - 1)
346-
const port = address.split(':')[1]
339+
const parts = address.split('/')
340+
// the url is in the form of hostname/ip:port
341+
if (parts.length > 1) {
342+
const hostname = parts[0]
343+
const port = parts[1].match(/((?::))(?:[0-9]+)$/g)[0].slice(1)
347344
address = `${hostname}:${port}`
348345
}
346+
349347
address = address.slice(0, 4) === 'http'
350348
? address
351349
: `${protocol}//${address}`

0 commit comments

Comments
 (0)