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

Commit

Permalink
Merge pull request #1372 from ionic-team/listen
Browse files Browse the repository at this point in the history
fix(serve): start listening when watch is ready
  • Loading branch information
imhoffd authored Jan 25, 2018
2 parents 2acf37d + 06bbd06 commit 09bd434
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/dev-server/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export function createHttpServer(config: ServeConfig): express.Application {

const app = express();
app.set('serveConfig', config);
app.listen(config.httpPort, config.host, function() {
Logger.debug(`listening on ${config.httpPort}`);
});

app.get('/', serveIndex);
app.use('/', express.static(config.wwwDir));
Expand Down
23 changes: 17 additions & 6 deletions src/serve.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as express from 'express';
import { BuildContext } from './util/interfaces';
import { getConfigValue, hasConfigValue } from './util/config';
import { BuildError } from './util/errors';
Expand All @@ -20,11 +21,24 @@ export function serve(context: BuildContext) {
setContext(context);

let config: ServeConfig;
let httpServer: express.Application;
const host = getHttpServerHost(context);
const notificationPort = getNotificationPort(context);
const liveReloadServerPort = getLiveReloadServerPort(context);
const hostPort = getHttpServerPort(context);

function finish() {
if (config) {
if (httpServer) {
httpServer.listen(config.httpPort, config.host, function() {
Logger.debug(`listening on ${config.httpPort}`);
});
}

onReady(config, context);
}
}

return findClosestOpenPorts(host, [notificationPort, liveReloadServerPort, hostPort])
.then(([notificationPortFound, liveReloadServerPortFound, hostPortFound]) => {
const hostLocation = (host === '0.0.0.0') ? 'localhost' : host;
Expand All @@ -51,12 +65,12 @@ export function serve(context: BuildContext) {

createNotificationServer(config);
createLiveReloadServer(config);
createHttpServer(config);
httpServer = createHttpServer(config);

return watch(context);
})
.then(() => {
onReady(config, context);
finish();
return config;
}, (err: BuildError) => {
throw err;
Expand All @@ -65,10 +79,7 @@ export function serve(context: BuildContext) {
if (err && err.isFatal) {
throw err;
} else {
if (config) {
onReady(config, context);
}

finish();
return config;
}
});
Expand Down

0 comments on commit 09bd434

Please sign in to comment.