calculate-server-name.js 449 B

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