How to define different routes for different host?

14 views
Skip to first unread message

Alexander Khasanov

unread,
Nov 30, 2014, 7:04:38 PM11/30/14
to perl...@googlegroups.com
Hi everyone,

How to define different routes for different host?

For example something like that:

sub build {
   
my $self = shift;
   
my $r    = $self->routes;
   
my $host = "";
    if ($host eq "domain1.com")
    {
    
    $r->add( '/home', 'home' );
        $r->add( '/config', sub { $_[0]->config_hash } );
    }
    else
    {
            $r->add( '/home1', 'home1' );
    }
}

And how to access to $ENV{HTTP_HOST} from build function?

Thanks!

Stefan Geneshky

unread,
Dec 1, 2014, 1:04:42 AM12/1/14
to perl...@googlegroups.com
Hi,

You can't define different routes based on the host name. I would suggest that you use different web applications for your different hosts.
 You can probably mount those applications either with mount (see examples here https://github.com/miyagawa/plack-handbook/blob/master/en/12_maps_multiple_apps_with_mount_and_urlmap.md ), or with nginx.

The entire contents of %ENV should be available in the build function.

Stefan

Alexander Khasanov

unread,
Dec 1, 2014, 11:57:13 AM12/1/14
to perl...@googlegroups.com
Thanks Stefan.

Is there any way to get requested domain name? 

понедельник, 1 декабря 2014 г., 1:04:42 UTC-5 пользователь Stefan Geneshky написал:

Stefan Geneshky

unread,
Dec 2, 2014, 12:23:16 AM12/2/14
to perl...@googlegroups.com
Perhaps you can make nginx (or your web server) pass the domain name in %ENV.
In nginx you could add this line to your proxy configuration:

proxy_set_header Host $host;

That'll add HOST to your %ENV.

Stefan
Reply all
Reply to author
Forward
0 new messages