domain support for feeds, factor out sc-specific bits
[scpubgit/SCS.git] / lib / SCSite / DevMode.pm
CommitLineData
99cee940 1package SCSite::DevMode;
2
3use Plack::App::File;
4use Plack::Runner;
9d4b4027 5use Try::Tiny;
99cee940 6use Moo::Role;
7
8has _static_handler => (is => 'lazy');
9
10sub _build__static_handler {
11 my ($self) = @_;
12 my $static_dir = $self->config->{static_dir};
7f2b58ea 13 Plack::App::File->new(root => $static_dir);
99cee940 14}
15
16around dispatch_request => sub {
17 my ($orig, $self) = (shift, shift);
18 no warnings::illegalproto;
19 (
99295c1b 20 sub (/**.*) {
21 my ($self, $path) = @_;
22 return unless $path =~ s/\/-/\//;
23 SCSite::redispatch_to "/static/${path}";
24 },
99cee940 25 sub (/static/...) { $self->_static_handler },
f08b95b6 26 sub (/favicon + .ico) { $self->_static_handler },
99cee940 27 $self->$orig(@_)
28 )
29};
30
31sub _run_dev_server {
32 my ($self, @args) = @_;
33 my $r = Plack::Runner->new(server => 'Starman', app => $self->to_psgi_app);
34 $r->parse_options(@args);
35 $r->set_options(argv => \@args);
36 $r->run;
37}
38
9d4b4027 39sub _run_dev_checkall {
40 my ($self) = @_;
41 my $ps = $self->pages;
42 foreach my $path ($ps->all_paths) {
43 try {
44 $ps->get({ path => $path });
45 print "OK ${path}\n";
46 } catch {
47 print "ERROR ${path}\n";
48 print " $_";
49 };
50 }
51}
52
99cee940 531;