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

Commit 7f04338

Browse files
committed
refactor(serve): add hostBaseUrl to serve config.
1 parent a7efc9e commit 7f04338

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/dev-server/serve-config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'path';
33
export interface ServeConfig {
44
httpPort: number;
55
host: string;
6+
hostBaseUrl: string;
67
rootDir: string;
78
wwwDir: string;
89
buildDir: string;
@@ -21,4 +22,4 @@ export const LOGGER_DIR = '__ion-dev-server';
2122
export const IONIC_LAB_URL = '/ionic-lab';
2223

2324
export const IOS_PLATFORM_PATH = path.join('platforms', 'ios', 'www');
24-
export const ANDROID_PLATFORM_PATH = path.join('platforms', 'android', 'assets', 'www');
25+
export const ANDROID_PLATFORM_PATH = path.join('platforms', 'android', 'assets', 'www');

src/serve.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('test serve', () => {
2222
};
2323
configResults = {
2424
httpPort: 8100,
25+
hostBaseUrl: 'http://localhost:8100',
2526
host: '0.0.0.0',
2627
rootDir: '/',
2728
wwwDir: '/www',

src/serve.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ export function serve(context: BuildContext) {
2525

2626
return findClosestOpenPort(host, notificationPort)
2727
.then((notificationPortFound) => {
28+
const hostPort = getHttpServerPort(context);
29+
const hostLocation = (host === '0.0.0.0') ? 'localhost' : host;
2830

2931
config = {
30-
httpPort: getHttpServerPort(context),
32+
httpPort: hostPort,
3133
host: host,
34+
hostBaseUrl: `http://${hostLocation}:${hostPort}`,
3235
rootDir: context.rootDir,
3336
wwwDir: context.wwwDir,
3437
buildDir: context.buildDir,
@@ -66,16 +69,15 @@ export function serve(context: BuildContext) {
6669
}
6770

6871
function onReady(config: ServeConfig, context: BuildContext) {
69-
const host = config.host === '0.0.0.0' ? 'localhost' : config.host;
7072
if (config.launchBrowser || config.launchLab) {
71-
const openOptions: string[] = [`http://${host}:${config.httpPort}`]
73+
const openOptions: string[] = [config.hostBaseUrl]
7274
.concat(launchLab(context) ? [IONIC_LAB_URL] : [])
7375
.concat(browserOption(context) ? [browserOption(context)] : [])
7476
.concat(platformOption(context) ? ['?ionicplatform=', platformOption(context)] : []);
7577

7678
open(openOptions.join(''), browserToLaunch(context));
7779
}
78-
Logger.info(`dev server running: http://${host}:${config.httpPort}/`, 'green', true);
80+
Logger.info(`dev server running: ${config.hostBaseUrl}/`, 'green', true);
7981
Logger.newLine();
8082
}
8183

0 commit comments

Comments
 (0)