blob: a8ba061c8d9c3a23f460e41dc85e67e34df8d81c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
'use strict';
const {isIP} = require('net');
const assert = require('assert');
const getHost = host => {
if (host[0] === '[') {
const idx = host.indexOf(']');
assert(idx !== -1);
return host.slice(1, idx);
}
const idx = host.indexOf(':');
if (idx === -1) {
return host;
}
return host.slice(0, idx);
};
module.exports = host => {
const servername = getHost(host);
if (isIP(servername)) {
return '';
}
return servername;
};
|