]> iEval git - gruntmaster-page.git/commitdiff
Merge branch 'master' into newmc
authorMarius Gavrilescu <marius@ieval.ro>
Sun, 1 Mar 2015 08:02:57 +0000 (10:02 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sun, 1 Mar 2015 08:02:57 +0000 (10:02 +0200)
1  2 
app.psgi

diff --combined app.psgi
index a4e0c34eca7da9c880ec0ee496a8e24e2be310c9,85e8847a44e8b7420e8cefca46ec862075f06cfe..728e144e4cf0b742cf7f22765925419d51f350e1
+++ b/app.psgi
@@@ -12,7 -12,7 +12,7 @@@ use Log::Log4perl
  use Tie::Hash::Expire;
  
  use constant AUTH_TIMEOUT => 5 * 60;
 -use constant ACCESSLOG_FORMAT => 'combined';
 +use constant ACCESSLOG_FORMAT => '%{X-Forwarded-For}i %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"';
  
  sub CONTENT_SECURITY_POLICY () {
        my $csp = <<CSP;
@@@ -20,16 -20,16 +20,16 @@@ default-src 'none
  connect-src 'self'
  form-action 'self'
  frame-ancestors 'none'
 -img-src 'self'
 +img-src 'self' https://static.mindcoding.ro https://www.google-analytics.com/collect
  referrer origin-when-cross-origin
 -script-src 'self'
 -style-src 'self'
 +script-src https://static.mindcoding.ro/js.js https://www.google-analytics.com/analytics.js
 +style-src https://static.mindcoding.ro/css/
  CSP
        chomp $csp;
        $csp =~ s/\n/; /gr;
  }
  
our $db //= Gruntmaster::Data->connect($ENV{GRUNTMASTER_DSN} // 'dbi:Pg:');
my $db;
  
  tie my %auth, 'Tie::Hash::Expire', {expire_seconds => AUTH_TIMEOUT};
  
@@@ -42,6 -42,16 +42,16 @@@ sub authenticate 
        $auth{key} = 1;
  }
  
+ sub add_database {
+       my $app = $_[0];
+       sub {
+               my ($env) = @_;
+               $db //= Gruntmaster::Data->connect($ENV{GRUNTMASTER_DSN} // 'dbi:Pg:');
+               $env->{'gruntmaster.dbic'} = $db;
+               $app->($env)
+       }
+ }
  sub add_headers {
        my $app = $_[0];
        sub {
@@@ -65,7 -75,7 +75,7 @@@ builder 
        enable \&add_headers;
        enable 'Static', path => qr,^/static/,;
        enable 'Log4perl', category => 'plack';
+       enable \&add_database;
        enable_if { shift->{HTTP_AUTHORIZATION} } 'Auth::Basic', authenticator => \&authenticate, realm => 'Gruntmaster 6000';
-       enable sub { my $app = $_[0]; sub { $_[0]->{'gruntmaster.dbic'} = $db; $app->($_[0]) } };
        Plack::App::Gruntmaster->run_if_script
  }
This page took 0.030386 seconds and 4 git commands to generate.