enable SSI
[scpubgit/App-SCS.git] / lib / App / SCS / Plugin / Server.pm
CommitLineData
f50b4a35 1package App::SCS::Plugin::Server;
2
3use Module::Runtime qw(use_module);
4use Moo;
5no warnings::illegalproto;
6
7with 'App::SCS::Role::Plugin';
8
9has _static_handler => (is => 'lazy');
10
11sub _build__static_handler {
12 my ($self) = @_;
13 use_module('Plack::App::File')->new(
14 root => $self->app->share_dir->catdir('static')
15 );
16}
17
18sub page_dispatchers {
19 my ($self) = @_;
20 sub (/**.*) {
21 my $path = $_[1];
0ea3d9ae 22 return unless $path =~ s/(?=\/|^)-//;
f50b4a35 23 App::SCS::Web::redispatch_to("/static/${path}");
24 },
25 sub (/static/...) { $self->_static_handler },
26 sub (/favicon + .ico) { $self->_static_handler },
27}
28
29sub run_command_server {
30 my ($self, $env) = @_;
31 my @args = @{$env->{argv}};
32 my $r = use_module('Plack::Runner')->new(
33 server => 'Starman',
bb6a4cec 34 app => use_module('Plack::Middleware::SSI')->wrap(
35 $self->app->web->to_psgi_app
36 )
f50b4a35 37 );
38 $r->parse_options(@args);
39 $r->set_options(argv => \@args);
40 $r->run;
41}
42
431;