diff --git a/packages/dart_frog_cli/lib/src/commands/dev/dev.dart b/packages/dart_frog_cli/lib/src/commands/dev/dev.dart index cef23ca4a..b3ba5e866 100644 --- a/packages/dart_frog_cli/lib/src/commands/dev/dev.dart +++ b/packages/dart_frog_cli/lib/src/commands/dev/dev.dart @@ -42,6 +42,7 @@ class DevCommand extends DartFrogCommand { 'hostname', abbr: 'H', help: 'Which host name the server should bind to.', + defaultsTo: 'localhost', ); } @@ -119,7 +120,7 @@ class DevCommand extends DartFrogCommand { final hostname = results['hostname'] as String?; io.InternetAddress? ip; - if (hostname != null) { + if (hostname != null && hostname != 'localhost') { ip = io.InternetAddress.tryParse(hostname); if (ip == null) { logger.err( diff --git a/packages/dart_frog_cli/lib/src/dev_server_runner/dev_server_runner.dart b/packages/dart_frog_cli/lib/src/dev_server_runner/dev_server_runner.dart index 301d17266..ae4dd3dc0 100644 --- a/packages/dart_frog_cli/lib/src/dev_server_runner/dev_server_runner.dart +++ b/packages/dart_frog_cli/lib/src/dev_server_runner/dev_server_runner.dart @@ -98,6 +98,7 @@ class DevServerRunner { final String port; /// Which host the server should start on. + /// It will default to localhost if empty. final io.InternetAddress? address; /// Which port number the dart vm service should listen on. @@ -148,7 +149,7 @@ class DevServerRunner { Future _codegen() async { logger.detail('[codegen] running pre-gen...'); final address = this.address; - logger.detail('Starting devserver host ${address?.address}'); + logger.detail('Starting development server on host ${address?.address}'); var vars = { 'port': port, if (address != null) 'host': address.address, @@ -332,7 +333,10 @@ class DevServerRunner { await _codegen(); await serve(); - final localhost = link(uri: Uri.parse('http://localhost:$port')); + + final hostAddress = address?.address ?? 'localhost'; + + final localhost = link(uri: Uri.parse('http://$hostAddress:$port')); progress.complete('Running on $localhost'); final cwdPath = workingDirectory.path; diff --git a/packages/dart_frog_cli/test/src/dev_server_runner/dev_server_runner_test.dart b/packages/dart_frog_cli/test/src/dev_server_runner/dev_server_runner_test.dart index 0e22c0c52..fa8cbdf50 100644 --- a/packages/dart_frog_cli/test/src/dev_server_runner/dev_server_runner_test.dart +++ b/packages/dart_frog_cli/test/src/dev_server_runner/dev_server_runner_test.dart @@ -148,6 +148,12 @@ void main() { onVarsChanged: any(named: 'onVarsChanged'), ), ).called(1); + + verify(() { + progress.complete('Running on ${link( + uri: Uri.parse('http://localhost:8080'), + )}'); + }).called(1); }); test('throws when server process is already running', () async { @@ -224,6 +230,12 @@ void main() { onVarsChanged: any(named: 'onVarsChanged'), ), ).called(1); + + verify(() { + progress.complete('Running on ${link( + uri: Uri.parse('http://localhost:4242'), + )}'); + }).called(1); }); test('custom address', () async { @@ -271,6 +283,12 @@ void main() { onVarsChanged: any(named: 'onVarsChanged'), ), ).called(1); + + verify(() { + progress.complete('Running on ${link( + uri: Uri.parse('http://192.162.1.2:4242'), + )}'); + }).called(1); }); test(