]> iEval git - gruntmaster-page.git/blame - app.psgi
fixed "Page 1 of 0" in job log
[gruntmaster-page.git] / app.psgi
CommitLineData
c492afe8 1#!/usr/bin/perl
7dc32473 2use v5.14;
c492afe8 3use warnings;
7dc32473 4
5a879d9a 5use Gruntmaster::Data;
7dc32473 6use Plack::App::Gruntmaster;
c85bf4a6 7use Plack::Builder;
3b69df7a 8use Plack::Util;
68d5c3ff
MG
9use Log::Log4perl;
10
031ffaf5
MG
11sub CONTENT_SECURITY_POLICY () {
12 my $csp = <<CSP;
13default-src 'none'
14connect-src 'self'
15form-action 'self'
16frame-ancestors 'none'
bd623b0d 17img-src 'self' https://static.mindcoding.ro
031ffaf5 18referrer origin-when-cross-origin
0f623f3d
MG
19script-src 'self'
20style-src 'self'
031ffaf5
MG
21CSP
22 chomp $csp;
23 $csp =~ s/\n/; /gr;
24}
c85bf4a6 25
be1da3f9
MG
26sub add_database {
27 my $app = $_[0];
28 sub {
10a4003f 29 dbinit $ENV{GRUNTMASTER_DSN} // 'dbi:Pg:' unless db;
1f64ef28 30 $app->(@_)
be1da3f9
MG
31 }
32}
33
3b69df7a
MG
34sub add_headers {
35 my $app = $_[0];
36 sub {
37 my $resp = $app->($_[0]);
38 my $hdrs = Plack::Util::headers($resp->[1]);
39 $hdrs->set('Content-Security-Policy', CONTENT_SECURITY_POLICY);
bbf6a6cc 40 $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,;
3b69df7a
MG
41 $resp->[1] = $hdrs->headers;
42 $resp;
43 }
44}
45
28b3c465 46Log::Log4perl->init_once('log.conf');
58a0ba09 47$ENV{DBIC_NULLABLE_KEY_NOWARN} = 1;
68d5c3ff 48
7dc32473 49builder {
28aeef34 50 enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }};
287424cb 51 enable 'ContentLength';
3b69df7a 52 enable \&add_headers;
bbf6a6cc 53 enable 'Static', path => qr,^/static/,;
68d5c3ff 54 enable 'Log4perl', category => 'plack';
be1da3f9 55 enable \&add_database;
8d725691
MG
56 enable '+Plack::App::Gruntmaster::Auth',
57 dbi_connect => [$ENV{GRUNTMASTER_DSN} // 'dbi:Pg:', '', ''],
58 realm => 'Gruntmaster 6000',
59 mail_from => $ENV{GRUNTMASTER_RESET_FROM};
594d53ba 60 Plack::App::Gruntmaster->run_if_script
7dc32473 61}
This page took 0.072491 seconds and 4 git commands to generate.