1+ import * as express from 'express' ;
12import { BuildContext } from './util/interfaces' ;
23import { getConfigValue , hasConfigValue } from './util/config' ;
34import { BuildError } from './util/errors' ;
@@ -20,11 +21,24 @@ export function serve(context: BuildContext) {
2021 setContext ( context ) ;
2122
2223 let config : ServeConfig ;
24+ let httpServer : express . Application ;
2325 const host = getHttpServerHost ( context ) ;
2426 const notificationPort = getNotificationPort ( context ) ;
2527 const liveReloadServerPort = getLiveReloadServerPort ( context ) ;
2628 const hostPort = getHttpServerPort ( context ) ;
2729
30+ function finish ( ) {
31+ if ( config ) {
32+ if ( httpServer ) {
33+ httpServer . listen ( config . httpPort , config . host , function ( ) {
34+ Logger . debug ( `listening on ${ config . httpPort } ` ) ;
35+ } ) ;
36+ }
37+
38+ onReady ( config , context ) ;
39+ }
40+ }
41+
2842 return findClosestOpenPorts ( host , [ notificationPort , liveReloadServerPort , hostPort ] )
2943 . then ( ( [ notificationPortFound , liveReloadServerPortFound , hostPortFound ] ) => {
3044 const hostLocation = ( host === '0.0.0.0' ) ? 'localhost' : host ;
@@ -51,12 +65,12 @@ export function serve(context: BuildContext) {
5165
5266 createNotificationServer ( config ) ;
5367 createLiveReloadServer ( config ) ;
54- createHttpServer ( config ) ;
68+ httpServer = createHttpServer ( config ) ;
5569
5670 return watch ( context ) ;
5771 } )
5872 . then ( ( ) => {
59- onReady ( config , context ) ;
73+ finish ( ) ;
6074 return config ;
6175 } , ( err : BuildError ) => {
6276 throw err ;
@@ -65,10 +79,7 @@ export function serve(context: BuildContext) {
6579 if ( err && err . isFatal ) {
6680 throw err ;
6781 } else {
68- if ( config ) {
69- onReady ( config , context ) ;
70- }
71-
82+ finish ( ) ;
7283 return config ;
7384 }
7485 } ) ;
0 commit comments