(protocol, host, port, pathname = '/')
| 22 | const isInteractive = process.stdout.isTTY; |
| 23 | |
| 24 | function prepareUrls(protocol, host, port, pathname = '/') { |
| 25 | const formatUrl = hostname => |
| 26 | url.format({ |
| 27 | protocol, |
| 28 | hostname, |
| 29 | port, |
| 30 | pathname, |
| 31 | }); |
| 32 | const prettyPrintUrl = hostname => |
| 33 | url.format({ |
| 34 | protocol, |
| 35 | hostname, |
| 36 | port: chalk.bold(port), |
| 37 | pathname, |
| 38 | }); |
| 39 | |
| 40 | const isUnspecifiedHost = host === '0.0.0.0' || host === '::'; |
| 41 | let prettyHost, lanUrlForConfig, lanUrlForTerminal; |
| 42 | if (isUnspecifiedHost) { |
| 43 | prettyHost = 'localhost'; |
| 44 | try { |
| 45 | // This can only return an IPv4 address |
| 46 | lanUrlForConfig = address.ip(); |
| 47 | if (lanUrlForConfig) { |
| 48 | // Check if the address is a private ip |
| 49 | // https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces |
| 50 | if ( |
| 51 | /^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test( |
| 52 | lanUrlForConfig |
| 53 | ) |
| 54 | ) { |
| 55 | // Address is private, format it for later use |
| 56 | lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig); |
| 57 | } else { |
| 58 | // Address is not private, so we will discard it |
| 59 | lanUrlForConfig = undefined; |
| 60 | } |
| 61 | } |
| 62 | } catch (_e) { |
| 63 | // ignored |
| 64 | } |
| 65 | } else { |
| 66 | prettyHost = host; |
| 67 | } |
| 68 | const localUrlForTerminal = prettyPrintUrl(prettyHost); |
| 69 | const localUrlForBrowser = formatUrl(prettyHost); |
| 70 | return { |
| 71 | lanUrlForConfig, |
| 72 | lanUrlForTerminal, |
| 73 | localUrlForTerminal, |
| 74 | localUrlForBrowser, |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | function printInstructions(appName, urls, useYarn) { |
| 79 | console.log(); |
no test coverage detected