Skip to content

Commit

Permalink
update message and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
renancaraujo committed Oct 30, 2023
1 parent 2726dfe commit a99a717
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/dart_frog_cli/lib/src/commands/dev/dev.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DevCommand extends DartFrogCommand {
'hostname',
abbr: 'H',
help: 'Which host name the server should bind to.',
defaultsTo: 'localhost',
);
}

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -148,7 +149,7 @@ class DevServerRunner {
Future<void> _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 = <String, dynamic>{
'port': port,
if (address != null) 'host': address.address,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a99a717

Please sign in to comment.