X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=app.psgi;h=20c8cb56f57a73f3c17f44ce03535e6aff9267bb;hb=refs%2Fheads%2Fnewmc-nodbic;hp=597e94167d5eebc968ea5e80ce6f66dd0937fe99;hpb=bffec365a2e7fa722c8a5ed515acdc3c07a3a4aa;p=gruntmaster-page.git diff --git a/app.psgi b/app.psgi index 597e941..20c8cb5 100644 --- a/app.psgi +++ b/app.psgi @@ -16,22 +16,18 @@ form-action 'self' frame-ancestors 'none' img-src 'self' https://static.mindcoding.ro referrer origin-when-cross-origin -script-src https://static.mindcoding.ro/static/js.js -style-src https://static.mindcoding.ro/static/css/ +script-src 'self' +style-src 'self' CSP chomp $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,7 +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('Link', '; rel=stylesheet') if $hdrs->get('Content-Type') =~ m,^text/html,; + $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,; $resp->[1] = $hdrs->headers; $resp; } @@ -54,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',