On Sun, May 7, 2017 at 12:28 AM, ivo welch <[email protected]> wrote:
> Mojo servers don't run / listen on a domain -- they listen on IPs. As >> such, it'll respond to whatever domain is pointed to the IP that routes to >> your Mojo server. So no, I don't think you can determine the domain before >> you start your app. >> > > ok. can I get the IP? all I need is learn whether I am operating on > 127.0.0.1 (or port 3000). > Same situation as port. I think the right way to do it is to use the config file that sets the ip/port in the first place. > I don't understand. We talked about this in another thread. What's the >> issue? >> > > because of browser buglets when localhost has subdomains. when localhost, > I must not set cookie_domain before the app starts. when I am on listening > on a real host, I want to set it. > Hmm... I wonder if the best way to do this is with mode <http://mojolicious.org/perldoc/Mojolicious#mode>. I assume you listen on localhost when in development mode, and on a real host you're in production mode. When you start your app with morbo or the daemon or prefork command, it's running in "development" mode. When you start with hypnotoad, it's running in production mode. By default. You can change the mode. So, the point is, rather than testing what IP it's listening on you might test what "mode" your app is running in. use Mojolicious::Lite; ... if ( app->mode eq 'production' ) { # do cookie stuff } else { # don't do cookie stuff } ... app->start; Also, all that logic before app->start happens before your Mojo Server even starts listening, so, no, you can't test what ip/port it's listening on because the server isn't running yet. That's why you'd use the config file (or if appropriate for your situation, the mode). Here's a test of that: *$ cat mode* use ojo; a("/" => sub { shift->render(inline => q(<%= app->mode %>)); }); warn; app->start; *$ perl mode daemon* Warning: something's wrong at mode line 4. Server available at http://127.0.0.1:3000 Notice how my warn statement happens before the Server becomes available at http://127.0.0.1:3000 -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
