From: Marius Gavrilescu Date: Sun, 1 Mar 2015 08:02:57 +0000 (+0200) Subject: Merge branch 'master' into newmc X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=a8dc218ceb178e05b574deed4090503fa9be3502;hp=228bfd242a3d9317246b99b55bbc89ce43d2caa2;p=plack-app-gruntmaster.git Merge branch 'master' into newmc --- diff --git a/app.psgi b/app.psgi index a4e0c34..728e144 100644 --- a/app.psgi +++ b/app.psgi @@ -29,7 +29,7 @@ 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 @@ 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 @@ 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 } diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index aa473d8..3a7b9db 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -116,7 +116,6 @@ sub dispatch_request{ }, sub (/robots.txt) { NOT_FOUND }, - sub (/favicon.ico) { NOT_FOUND }, sub (/src/:job) { return NOT_FOUND if !job;