Skip to content

jberger/mojolicious-plugin-vhost

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

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.

About

VirtualHosts for Mojolicious

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Perl 100.0%