The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojolicious::Plugin::VHost - Mojolicious Plugin that adds VirtualHosts

SYNOPSIS

  # Mojolicious
  $self->plugin('JSONConfig');
  $self->plugin('VHost');

DESCRIPTION

Mojolicious::Plugin::VHost adds virtualhosts to Mojolicious.

CONFIGURATION

One supported method of configuration is with the JSONConfig plugin. Add vhosts with a config such as:

    {
        "VHost":
            {
                "host1":{"routes":["VHost::First::Controller"],"static":["public\/first"],"templates":["templates\/first"]},
                "host2":{"routes":["VHost::Another::Controller"],"static":["public\/another"],"templates":["templates\/another"]}
            }
    }

host1 and host2 are the Host: header field and must match exactly. The following route format has been tested:

  $r->get('/')->to(controller => 'Index', action => 'slash');
  $r->get('/:name')->to(controller => 'Index', action => 'slash');

For host1, "/" would route to lib/VHost/First/Index.pm; static files would be in public/first; and templates would be found in templates/first.

A full startup sub is:

    sub startup {
      my $self = shift;

      $self->plugin('JSONConfig');
      $self->plugin('VHost');

      # Router
      my $r = $self->routes;

      $r->get('/')->to(controller => 'Index', action => 'slash');
      $r->get('/:name')->to(controller => 'Index', action => 'slash');
    }

METHODS

Mojolicious::Plugin::VHost inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

  $plugin->register(Mojolicious->new);

Register plugin in Mojolicious application.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.