Commit | Line | Data |
f50b4a35 |
1 | package App::SCS::Plugin::Server; |
2 | |
3 | use Module::Runtime qw(use_module); |
4 | use Moo; |
5 | no warnings::illegalproto; |
6 | |
7 | with 'App::SCS::Role::Plugin'; |
8 | |
9 | has _static_handler => (is => 'lazy'); |
10 | |
11 | sub _build__static_handler { |
12 | my ($self) = @_; |
13 | use_module('Plack::App::File')->new( |
14 | root => $self->app->share_dir->catdir('static') |
15 | ); |
16 | } |
17 | |
18 | sub 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 | |
29 | sub 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 | |
43 | 1; |