X-Git-Url: http://git.ieval.ro/?p=plack-app-gruntmaster.git;a=blobdiff_plain;f=app.psgi;h=3a6be219ec8fe3f4a5a53a714247e9a8dbdcfa22;hp=f7c85ffec3149dbd1bba33486039966bb74dfd92;hb=1f64ef28e31c592b91d5d75850229e01e7f89b84;hpb=6d4b4529219434f5d50dd28e17b6bda0e957864d diff --git a/app.psgi b/app.psgi index f7c85ff..3a6be21 100644 --- a/app.psgi +++ b/app.psgi @@ -1,6 +1,6 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl use v5.14; -no if $] >= 5.017011, warnings => 'experimental::smartmatch'; +use warnings; use Gruntmaster::Data; use Plack::App::Gruntmaster; @@ -8,9 +8,6 @@ use Plack::Builder; use Plack::Util; use Log::Log4perl; -use constant AUTH_TIMEOUT => 5 * 60; -use constant ACCESSLOG_FORMAT => 'combined'; - sub CONTENT_SECURITY_POLICY () { my $csp = <connect($ENV{GRUNTMASTER_DSN} // 'dbi:Pg:'); - $env->{'gruntmaster.dbic'} = $db; - $app->($env) + Gruntmaster::Data::init $ENV{GRUNTMASTER_DSN} // 'dbi:Pg:' unless $dbinit; + $dbinit = 1; + $app->(@_) } } @@ -44,7 +40,6 @@ 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; @@ -52,12 +47,10 @@ sub add_headers { } Log::Log4perl->init_once('log.conf'); -my $access_logger = Log::Log4perl->get_logger('access'); $ENV{DBIC_NULLABLE_KEY_NOWARN} = 1; builder { enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }}; - enable 'AccessLog', format => ACCESSLOG_FORMAT, logger => sub { $access_logger->info(@_) }; enable 'ContentLength'; enable \&add_headers; enable 'Static', path => qr,^/static/,;