$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};
$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 {
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
}