App-Alice
view release on metacpan or search on metacpan
lib/App/Alice/HTTPD.pm view on Meta::CPAN
package App::Alice::HTTPD;
use AnyEvent;
use AnyEvent::HTTP;
use Twiggy::Server;
use Plack::Request;
use Plack::Builder;
use Plack::Middleware::Static;
use Plack::Session::Store::File;
use IRC::Formatting::HTML qw/html_to_irc/;
use App::Alice::Stream;
use App::Alice::Commands;
use JSON;
use Encode;
use utf8;
use Any::Moose;
use Try::Tiny;
has 'app' => (
is => 'ro',
isa => 'App::Alice',
required => 1,
);
has 'httpd' => (is => 'rw');
has 'ping_timer' => (is => 'rw');
has 'config' => (
is => 'ro',
isa => 'App::Alice::Config',
lazy => 1,
default => sub {shift->app->config},
);
my $url_handlers = [
[ qr{^/$} => \&send_index ],
[ qr{^/say/?$} => \&handle_message ],
[ qr{^/stream/?$} => \&setup_stream ],
[ qr{^/config/?$} => \&send_config ],
[ qr{^/prefs/?$} => \&send_prefs ],
[ qr{^/serverconfig/?$} => \&server_config ],
[ qr{^/save/?$} => \&save_config ],
[ qr{^/tabs/?$} => \&tab_order ],
[ qr{^/login/?$} => \&login ],
[ qr{^/logout/?$} => \&logout ],
[ qr{^/logs/?$} => \&send_logs ],
[ qr{^/search/?$} => \&send_search ],
[ qr{^/range/?$} => \&send_range ],
[ qr{^/view/?$} => \&send_index ],
[ qr{^/get} => \&image_proxy ],
];
sub url_handlers { return $url_handlers }
has 'streams' => (
is => 'rw',
auto_deref => 1,
isa => 'ArrayRef[App::Alice::Stream]',
default => sub {[]},
);
sub add_stream {push @{shift->streams}, @_}
sub no_streams {@{$_[0]->streams} == 0}
sub stream_count {scalar @{$_[0]->streams}}
sub BUILD {
my $self = shift;
my $httpd = Twiggy::Server->new(
host => $self->config->http_address,
port => $self->config->http_port,
);
$httpd->register_service(
builder {
if ($self->app->auth_enabled) {
mkdir $self->config->path."/sessions"
unless -d $self->config->path."/sessions";
enable "Session",
( run in 1.227 second using v1.01-cache-2.11-cpan-39bf76dae61 )