Blame view

node_modules/webpack-dev-server/lib/util/createDomain.js 747 Bytes
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  'use strict';
  
  const url = require('url');
  const internalIp = require('internal-ip');
  
  
  module.exports = function createDomain(options, listeningApp) {
    const protocol = options.https ? 'https' : 'http';
    const appPort = listeningApp ? listeningApp.address().port : 0;
    const port = options.socket ? 0 : appPort;
    const hostname = options.useLocalIp ? internalIp.v4() : options.host;
  
    // use explicitly defined public url (prefix with protocol if not explicitly given)
    if (options.public) {
      return /^[a-zA-Z]+:\/\//.test(options.public) ? `${options.public}` : `${protocol}://${options.public}`;
    }
    // the formatted domain (url without path) of the webpack server
    return url.format({
      protocol,
      hostname,
      port
    });
  };