mojolicious / mojo

:sparkles: Mojolicious - Perl real-time web framework
https://mojolicious.org
Artistic License 2.0
2.66k stars 577 forks source link

Mojo::Server::Daemon show wrong listen address #899

Closed hexsum closed 8 years ago

hexsum commented 8 years ago
use Mojo::Server::Daemon;
Mojo::Server::Daemon->new(listen=>["http://*:3000/"])->run()

print the following message:

Server available at http://127.0.0.1:3000/

but actually the server is listenging on ‘0.0.0.0’

$netstat -anp|grep LISTEN
tcp        0      0  0.0.0.0:3000          0.0.0.0:*       LISTEN      19244/perl

I think this makes people confused.

Also, I think the following source code in Mojo/Server/Daemon.pm is ugly and unfriendly and inconsistent with the context

199. return if $self->silent;
200. $self->app->log->info(qq{Listening at "$url"});
201. $query->pairs([]);
202. $url->host('127.0.0.1') if $url->host eq '*';
203. say "Server available at $url";
204.}

line 200: the $self->app->log->info actually doesn't work because the default app Mojo::HelloWorld set the log level as "error"

line 202: Should this line be $url->host('0.0.0.0') if $url->host eq '*';

line 203:I don't understand why we don't write $self->app->log->info("Server available at $url") instead of say "Server available at $url"

a path may be like this:

diff --git a/lib/Mojo/HelloWorld.pm b/lib/Mojo/HelloWorld.pm
index 7326296..536e7ba 100644
--- a/lib/Mojo/HelloWorld.pm
+++ b/lib/Mojo/HelloWorld.pm
@@ -1,7 +1,7 @@
 package Mojo::HelloWorld;
 use Mojolicious::Lite;

-app->log->level('error')->path(undef);
+app->log->level('info')->path(undef);

 any '/*whatever' => {whatever => '', text => 'Your Mojo is working!'};

diff --git a/lib/Mojo/Server/Daemon.pm b/lib/Mojo/Server/Daemon.pm
index 024d92d..296e397 100644
--- a/lib/Mojo/Server/Daemon.pm
+++ b/lib/Mojo/Server/Daemon.pm
@@ -199,8 +199,8 @@ sub _listen {
   return if $self->silent;
   $self->app->log->info(qq{Listening at "$url"});
   $query->pairs([]);
-  $url->host('127.0.0.1') if $url->host eq '*';
-  say "Server available at $url";
+  $url->host('0.0.0.0') if $url->host eq '*';
+  $self->app->log->info("Server available at $url");
 }

 sub _read {
hexsum commented 8 years ago

I Just find out the "Server available" in many place......

find ./ -type f|xargs grep 'Server available at'
./lib/Mojolicious/Guides/Cookbook.pod:  Server available at http://127.0.0.1:3000
./lib/Mojolicious/Guides/Cookbook.pod:  Server available at https://[::]:3000
./lib/Mojolicious/Guides/Cookbook.pod:  Server available at http://127.0.0.1:3000
./lib/Mojolicious/Guides/Cookbook.pod:  Server available at http://127.0.0.1:3000
./lib/Mojolicious/Guides/Cookbook.pod:  Server available at http://127.0.0.1:3000
./lib/Mojolicious/Guides/Cookbook.pod:  Server available at http://127.0.0.1:8080
./lib/Mojolicious/Guides/Cookbook.pod:  Server available at http://127.0.0.1:8080
./lib/Mojolicious/Guides/Growing.pod:  Server available at http://127.0.0.1:3000
./lib/Mojolicious/Guides/Tutorial.pod:  Server available at http://127.0.0.1:3000
./lib/Mojolicious/Guides/Tutorial.pod:  Server available at http://127.0.0.1:8080
./lib/Mojolicious/Guides/Tutorial.pod:  Server available at http://127.0.0.1:3000
./lib/Mojo/Server/Daemon.pm:  $self->app->log->info("Server available at $url");
./lib/Mojo/Server/Morbo.pm:  Server available at http://127.0.0.1:3000
./README.md:    Server available at http://127.0.0.1:3000
kraih commented 8 years ago

I'm afraid this inconsistency is intentional, we used to get regular complaints when the message didn't say "http://127.0.0.1:3000" back in the days. In fact, you're the first one to complain about this version in years. So, i believe that no changes are necessary.

hexsum commented 8 years ago

ok, I am a perfectionist and Obsessive compulsive disorder

abraxxa commented 1 year ago

Picking up this issue instead of opening a new one. Using the vite proxy feature of quasar to http://localhost:3000 lead to a non-working configuration when my host has IPv6 connectivity because localhost then resolves to ::1 instead of 127.0.0.1. I'd suggest to keep that configuration case in mind and listen on all available IP protocols or IPv6 only. Maybe the underlying code already supports using localhost instead of 127.0.0.1 which might fix the issue as well.