@@ -9,6 +9,7 @@ import { createNotificationServer } from './dev-server/notification-server';
9
9
import { createHttpServer } from './dev-server/http-server' ;
10
10
import { createLiveReloadServer } from './dev-server/live-reload' ;
11
11
import { ServeConfig , IONIC_LAB_URL } from './dev-server/serve-config' ;
12
+ import { findClosestOpenPort } from './util/network' ;
12
13
13
14
const DEV_LOGGER_DEFAULT_PORT = 53703 ;
14
15
const LIVE_RELOAD_DEFAULT_PORT = 35729 ;
@@ -17,29 +18,38 @@ const DEV_SERVER_DEFAULT_HOST = '0.0.0.0';
17
18
18
19
export function serve ( context : BuildContext ) {
19
20
setContext ( context ) ;
20
- const config : ServeConfig = {
21
- httpPort : getHttpServerPort ( context ) ,
22
- host : getHttpServerHost ( context ) ,
23
- rootDir : context . rootDir ,
24
- wwwDir : context . wwwDir ,
25
- buildDir : context . buildDir ,
26
- isCordovaServe : isCordovaServe ( context ) ,
27
- launchBrowser : launchBrowser ( context ) ,
28
- launchLab : launchLab ( context ) ,
29
- browserToLaunch : browserToLaunch ( context ) ,
30
- useLiveReload : useLiveReload ( context ) ,
31
- liveReloadPort : getLiveReloadServerPort ( context ) ,
32
- notificationPort : getNotificationPort ( context ) ,
33
- useServerLogs : useServerLogs ( context ) ,
34
- useProxy : useProxy ( context ) ,
35
- notifyOnConsoleLog : sendClientConsoleLogs ( context )
36
- } ;
37
-
38
- createNotificationServer ( config ) ;
39
- createLiveReloadServer ( config ) ;
40
- createHttpServer ( config ) ;
41
-
42
- return watch ( context )
21
+
22
+ let config : ServeConfig ;
23
+ const notificationPort = getNotificationPort ( context ) ;
24
+ const host = getHttpServerHost ( context ) ;
25
+
26
+ return findClosestOpenPort ( host , notificationPort )
27
+ . then ( ( notificationPortFound ) => {
28
+
29
+ config = {
30
+ httpPort : getHttpServerPort ( context ) ,
31
+ host : host ,
32
+ rootDir : context . rootDir ,
33
+ wwwDir : context . wwwDir ,
34
+ buildDir : context . buildDir ,
35
+ isCordovaServe : isCordovaServe ( context ) ,
36
+ launchBrowser : launchBrowser ( context ) ,
37
+ launchLab : launchLab ( context ) ,
38
+ browserToLaunch : browserToLaunch ( context ) ,
39
+ useLiveReload : useLiveReload ( context ) ,
40
+ liveReloadPort : getLiveReloadServerPort ( context ) ,
41
+ notificationPort : notificationPortFound ,
42
+ useServerLogs : useServerLogs ( context ) ,
43
+ useProxy : useProxy ( context ) ,
44
+ notifyOnConsoleLog : sendClientConsoleLogs ( context )
45
+ } ;
46
+
47
+ createNotificationServer ( config ) ;
48
+ createLiveReloadServer ( config ) ;
49
+ createHttpServer ( config ) ;
50
+
51
+ return watch ( context ) ;
52
+ } )
43
53
. then ( ( ) => {
44
54
onReady ( config , context ) ;
45
55
} , ( err : BuildError ) => {
0 commit comments