1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const url = require('url');
|
9 | const ip = require('internal-ip');
|
10 |
|
11 | function createDomain(options, server) {
|
12 | const protocol = options.https ? 'https' : 'http';
|
13 | const hostname = options.useLocalIp
|
14 | ? ip.v4.sync() || 'localhost'
|
15 | : options.host;
|
16 |
|
17 | const port = options.socket ? 0 : server ? server.address().port : 0;
|
18 |
|
19 |
|
20 | if (options.public) {
|
21 | return /^[a-zA-Z]+:\/\//.test(options.public)
|
22 | ? `${options.public}`
|
23 | : `${protocol}://${options.public}`;
|
24 | }
|
25 |
|
26 | return url.format({
|
27 | protocol,
|
28 | hostname,
|
29 | port,
|
30 | });
|
31 | }
|
32 |
|
33 | module.exports = createDomain;
|