Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 06bbd06

Browse files
committed
fix(serve): start listening when watch is ready
1 parent 2acf37d commit 06bbd06

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/dev-server/http-server.ts

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export function createHttpServer(config: ServeConfig): express.Application {
2828

2929
const app = express();
3030
app.set('serveConfig', config);
31-
app.listen(config.httpPort, config.host, function() {
32-
Logger.debug(`listening on ${config.httpPort}`);
33-
});
3431

3532
app.get('/', serveIndex);
3633
app.use('/', express.static(config.wwwDir));

src/serve.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as express from 'express';
12
import { BuildContext } from './util/interfaces';
23
import { getConfigValue, hasConfigValue } from './util/config';
34
import { 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

Comments
 (0)