Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

createDomain.js 850 B

3 anos atrás
1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. /* eslint-disable
  3. no-nested-ternary,
  4. multiline-ternary,
  5. space-before-function-paren
  6. */
  7. const url = require('url');
  8. const ip = require('internal-ip');
  9. function createDomain (options, server) {
  10. const protocol = options.https ? 'https' : 'http';
  11. const hostname = options.useLocalIp ? ip.v4.sync() || 'localhost' : options.host;
  12. const port = options.socket
  13. ? 0
  14. : server
  15. ? server.address().port
  16. : 0;
  17. // use explicitly defined public url
  18. // (prefix with protocol if not explicitly given)
  19. if (options.public) {
  20. return /^[a-zA-Z]+:\/\//.test(options.public)
  21. ? `${options.public}`
  22. : `${protocol}://${options.public}`;
  23. }
  24. // the formatted domain (url without path) of the webpack server
  25. return url.format({
  26. protocol,
  27. hostname,
  28. port
  29. });
  30. }
  31. module.exports = createDomain;