+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)
+ }
+}
+
+sub add_headers {
+ my $app = $_[0];
+ sub {
+ my $resp = $app->($_[0]);
+ my $hdrs = Plack::Util::headers($resp->[1]);
+ $hdrs->set('Content-Security-Policy', CONTENT_SECURITY_POLICY);
+ $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,;
+ $resp->[1] = $hdrs->headers;
+ $resp;
+ }
+}
+
+Log::Log4perl->init_once('log.conf');
+$ENV{DBIC_NULLABLE_KEY_NOWARN} = 1;
+