Skip to content

Commit fc6020f

Browse files
committed
feat(cordova): --external option for hosting dev server on 0.0.0.0
Instead of using `--address=0.0.0.0`, you can now use `--external`
1 parent e97f868 commit fc6020f

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

packages/ionic/src/commands/cordova/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class RunCommand extends CordovaCommand implements CommandPreRun {
4848
const exampleCommands = [
4949
...CORDOVA_BUILD_EXAMPLE_COMMANDS,
5050
'android -l',
51-
'ios --livereload',
51+
'ios --livereload --external',
5252
'ios --livereload-url=http://localhost:8100',
5353
].sort();
5454

packages/ionic/src/lib/__tests__/serve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ describe('ionic', () => {
5555
expect(result).toEqual({ ...defaults, address: '0.0.0.0', port: 1111 });
5656
});
5757

58-
it('should respect --local flag', () => {
58+
it('should respect --external flag', () => {
5959
const runner = new MyServeRunner({});
60-
const result = runner.createOptionsFromCommandLine([], { _: [], local: true });
61-
expect(result).toEqual({ ...defaults, address: 'localhost', devapp: false });
60+
const result = runner.createOptionsFromCommandLine([], { _: [], external: true });
61+
expect(result).toEqual({ ...defaults, address: '0.0.0.0', devapp: false });
6262
});
6363

6464
it('should respect --project flag', () => {

packages/ionic/src/lib/serve.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export const BROWSERS = ['safari', 'firefox', process.platform === 'win32' ? 'ch
4242
export const SERVE_SCRIPT = 'ionic:serve';
4343

4444
export const COMMON_SERVE_COMMAND_OPTIONS: readonly CommandMetadataOption[] = [
45+
{
46+
name: 'external',
47+
summary: `Host dev server on all network interfaces (i.e. ${input('--address=0.0.0.0')})`,
48+
type: Boolean,
49+
},
4550
{
4651
name: 'address',
4752
summary: 'Use specific address for the dev server',
@@ -105,7 +110,7 @@ export abstract class ServeRunner<T extends ServeOptions> implements Runner<T, S
105110
createOptionsFromCommandLine(inputs: CommandLineInputs, options: CommandLineOptions): ServeOptions {
106111
const separatedArgs = options['--'];
107112

108-
if (options['devapp'] && options['address'] === DEFAULT_ADDRESS) {
113+
if (options['external'] || (options['devapp'] && options['address'] === DEFAULT_ADDRESS)) {
109114
options['address'] = '0.0.0.0';
110115
}
111116

@@ -393,7 +398,7 @@ export abstract class ServeRunner<T extends ServeOptions> implements Runner<T, S
393398
this.e.log.warn(
394399
'An external host may be required to serve for this target device/platform.\n' +
395400
'If you get connection issues on your device or emulator, try connecting the device to the same Wi-Fi network and selecting an accessible IP address for your computer on that network.\n\n' +
396-
`You can use ${input('--address=0.0.0.0')} to run the dev server on all network interfaces, in which case an external address will be selected.\n`
401+
`You can use ${input('--external')} to run the dev server on all network interfaces, in which case an external address will be selected.\n`
397402
);
398403
}
399404

0 commit comments

Comments
 (0)