make dev mode server serve favicon.ico
[scpubgit/SCS.git] / lib / SCSite / DevMode.pm
CommitLineData
99cee940 1package SCSite::DevMode;
2
3use Plack::App::File;
4use Plack::Runner;
5use Moo::Role;
6
7has _static_handler => (is => 'lazy');
8
9sub _build__static_handler {
10 my ($self) = @_;
11 my $static_dir = $self->config->{static_dir};
12 Plack::App::File->new(root => $static_dir)->to_app;
13}
14
15around dispatch_request => sub {
16 my ($orig, $self) = (shift, shift);
17 no warnings::illegalproto;
18 (
19 sub (/static/...) { $self->_static_handler },
f08b95b6 20 sub (/favicon + .ico) { $self->_static_handler },
99cee940 21 $self->$orig(@_)
22 )
23};
24
25sub _run_dev_server {
26 my ($self, @args) = @_;
27 my $r = Plack::Runner->new(server => 'Starman', app => $self->to_psgi_app);
28 $r->parse_options(@args);
29 $r->set_options(argv => \@args);
30 $r->run;
31}
32
331;