fixed "Page 1 of 0" in job log
[gruntmaster-page.git] / app.psgi
index a13a73e4965ba82ca2d26b8a40a8c094d2bb3094..20c8cb56f57a73f3c17f44ce03535e6aff9267bb 100644 (file)
--- a/app.psgi
+++ b/app.psgi
@@ -23,15 +23,11 @@ CSP
        $csp =~ s/\n/; /gr;
 }
 
-my $db;
-
 sub add_database {
        my $app = $_[0];
        sub {
-               my ($env) = @_;
-               $db //= Gruntmaster::Data->connect($ENV{GRUNTMASTER_DSN} // 'dbi:Pg:');
-               $env->{'gruntmaster.dbic'} = $db;
-               $app->($env)
+               dbinit $ENV{GRUNTMASTER_DSN} // 'dbi:Pg:' unless db;
+               $app->(@_)
        }
 }
 
@@ -41,6 +37,7 @@ sub add_headers {
                my $resp = $app->($_[0]);
                my $hdrs = Plack::Util::headers($resp->[1]);
                $hdrs->set('Content-Security-Policy', CONTENT_SECURITY_POLICY);
+               $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,;
                $resp->[1] = $hdrs->headers;
                $resp;
        }
@@ -53,6 +50,7 @@ builder {
        enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }};
        enable 'ContentLength';
        enable \&add_headers;
+       enable 'Static', path => qr,^/static/,;
        enable 'Log4perl', category => 'plack';
        enable \&add_database;
        enable '+Plack::App::Gruntmaster::Auth',
This page took 0.010151 seconds and 4 git commands to generate.