| 1 | package Miril::App::Cmd::Command::server; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use autodie; | ||
| 6 | |||
| 7 | use Miril::App::Cmd -command; | ||
| 8 | |||
| 9 | use Class::Autouse; | ||
| 10 | Class::Autouse->autouse('Plack::Loader'); | ||
| 11 | Class::Autouse->autouse('Miril::App::PSGI'); | ||
| 12 | |||
| 13 | sub opt_spec | ||
| 14 | { | ||
| 15 | return ( | ||
| 16 | [ 'host|h=s', "host address to bind to", { default => 'localhost' } ], | ||
| 17 | [ 'port|p=i', "port to listen on", { default => 8080 } ], | ||
| 18 | [ 'dir|d=s', "miril base dir", { default => 'example' } ], | ||
| 19 | [ 'site|s=s', "website", { default => 'example.com' } ], | ||
| 20 | ); | ||
| 21 | } | ||
| 22 | |||
| 23 | sub execute | ||
| 24 | { | ||
| 25 | my ($self, $opt, $args) = @_; | ||
| 26 | |||
| 27 | print "Miril accepting connections at http://" . $opt->host . ":" . $opt->port ."\n"; | ||
| 28 | |||
| 29 | Plack::Loader->auto( | ||
| 30 | host => $opt->host, | ||
| 31 | port => $opt->port, | ||
| 32 | )->run( | ||
| 33 | Miril::App::PSGI->app($opt->dir, $opt->site) | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 |