@@ -13,6 +13,7 @@ var projectConfig = require('./../projectConfig');
1313var jobs_logs = require ( './../jobs/logs.js' ) ;
1414var jobs_waitfor = require ( './../jobs/waitfor.js' ) ;
1515var jobs_show = require ( './../jobs/show.js' ) ;
16+ const chalk = require ( 'chalk' ) ;
1617
1718/**
1819 * @memberof jobs
@@ -136,6 +137,32 @@ function directorySize(_path, cb, size) {
136137 } ) ;
137138}
138139
140+ function LinksFromIpPortMappings ( ipAddress , ports ) {
141+ var result = [ ] ;
142+ var portMappings = ( '' + ports ) . split ( "," ) ;
143+ for ( var i = 0 ; i < portMappings . length ; i ++ ) {
144+ var portMapping = portMappings [ i ] ;
145+ var portMappingParts = portMapping . split ( ":" ) ;
146+ if ( portMappingParts . length > 0 ) {
147+ var portMappedTo = portMappingParts [ 0 ] . trim ( ) ;
148+ if ( portMappedTo ) {
149+ var scheme = 'http' ;
150+ if ( portMappingParts . length > 2 ) {
151+ var portMappingSchme = portMappingParts [ 2 ] . trim ( ) ;
152+ if ( portMappingSchme ) scheme = portMappingSchme ;
153+ } else if ( portMappingParts . length > 1 ) {
154+ var portMappedFrom = portMappingParts [ 1 ] . trim ( ) ;
155+ if ( portMappedFrom == '22' ) scheme = 'ssh' ;
156+ if ( portMappedFrom == '443' ) scheme = 'https' ;
157+ }
158+ var link = scheme + '://' + ipAddress + ':' + portMappedTo + '/' ;
159+ result . push ( link ) ;
160+ }
161+ }
162+ }
163+ return result ;
164+ }
165+
139166var MAX_UPLOAD_SIZE = 104857600 ; // 100MB
140167
141168function create ( params , cb ) {
@@ -244,7 +271,19 @@ function create(params, cb) {
244271 return cb ( ) ;
245272 }
246273 if ( res . storageRegion ) console . log ( 'Storage Region: ' + res . storageRegion ) ;
247- if ( res . ports && res . ipAddress ) console . log ( 'IP Address: ' + res . ipAddress ) ;
274+ if ( res . ports && res . ipAddress ) {
275+ var links = LinksFromIpPortMappings ( res . ipAddress , res . ports ) ;
276+ if ( links . length > 0 ) {
277+ var link_str = '' ;
278+ for ( var i = 0 ; i < links . length ; i ++ ) {
279+ var link = links [ i ] ;
280+ if ( i > 0 ) link_str += ', ' ;
281+ link_str += chalk . underline ( link ) ;
282+ }
283+ if ( links . length > 1 ) console . log ( 'Links: ' + link_str ) ;
284+ else console . log ( 'Link: ' + link_str ) ;
285+ } else console . log ( 'IP Address: ' + res . ipAddress ) ;
286+ }
248287 console . log ( 'Awaiting logs...' ) ;
249288 return jobs_logs ( { jobId : jobId , tail : true } , function _logsCb ( err ) {
250289 if ( err ) return cb ( err ) ;
0 commit comments