import * as url from "url" ; import * as address from "address" ; import chalk from "chalk" ; export interface InstructionURLS { lanUrlForConfig ? : string ; lanUrlForTerminal ? : string ; localUrlForTerminal ? : string ; localUrlForBrowser : string ; } export default function prepareUrls ( protocol , host , port , pathname = "/" ) { const formatUrl = ( hostname ) => url . format ( { protocol , hostname , port , pathname , } ) ; const prettyPrintUrl = ( hostname ) => url . format ( { protocol , hostname , port : chalk . bold ( port ) , pathname , } ) ; const isUnspecifiedHost = host === "0.0.0.0" || host === "::" ; let prettyHost ; let lanUrlForConfig = undefined ; let lanUrlForTerminal = undefined ; if ( isUnspecifiedHost ) { prettyHost = "localhost" ; try { lanUrlForConfig = address . ip ( ) as string ; if ( lanUrlForConfig ) { if ( /^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/ . test ( lanUrlForConfig ) ) { lanUrlForTerminal = prettyPrintUrl ( lanUrlForConfig ) ; } else { lanUrlForConfig = undefined ; } } } catch ( _e ) { } } else { prettyHost = host ; } const localUrlForTerminal = prettyPrintUrl ( prettyHost ) ; const localUrlForBrowser = formatUrl ( prettyHost ) ; return { lanUrlForConfig , lanUrlForTerminal , localUrlForTerminal , localUrlForBrowser , } ; }