]> iEval git - gruntmaster-page.git/blame - app.psgi
Add close button styles
[gruntmaster-page.git] / app.psgi
CommitLineData
7dc32473
MG
1#!/usr/bin/perl -w
2use v5.14;
491e82eb 3no if $] >= 5.017011, warnings => 'experimental::smartmatch';
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
594d53ba 11use constant AUTH_TIMEOUT => 5 * 60;
5ab9964f 12use constant ACCESSLOG_FORMAT => 'combined';
031ffaf5
MG
13
14sub CONTENT_SECURITY_POLICY () {
15 my $csp = <<CSP;
16default-src 'none'
17connect-src 'self'
18form-action 'self'
19frame-ancestors 'none'
20img-src 'self'
21referrer origin-when-cross-origin
22script-src 'self'
23style-src 'self'
24CSP
25 chomp $csp;
26 $csp =~ s/\n/; /gr;
27}
c85bf4a6 28
be1da3f9 29my $db;
5a879d9a 30
be1da3f9
MG
31sub add_database {
32 my $app = $_[0];
33 sub {
34 my ($env) = @_;
35 $db //= Gruntmaster::Data->connect($ENV{GRUNTMASTER_DSN} // 'dbi:Pg:');
36 $env->{'gruntmaster.dbic'} = $db;
37 $app->($env)
38 }
39}
40
3b69df7a
MG
41sub add_headers {
42 my $app = $_[0];
43 sub {
44 my $resp = $app->($_[0]);
45 my $hdrs = Plack::Util::headers($resp->[1]);
46 $hdrs->set('Content-Security-Policy', CONTENT_SECURITY_POLICY);
47 $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,;
48 $resp->[1] = $hdrs->headers;
49 $resp;
50 }
51}
52
28b3c465 53Log::Log4perl->init_once('log.conf');
68d5c3ff 54my $access_logger = Log::Log4perl->get_logger('access');
58a0ba09 55$ENV{DBIC_NULLABLE_KEY_NOWARN} = 1;
68d5c3ff 56
7dc32473 57builder {
28aeef34 58 enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }};
68d5c3ff 59 enable 'AccessLog', format => ACCESSLOG_FORMAT, logger => sub { $access_logger->info(@_) };
287424cb 60 enable 'ContentLength';
3b69df7a 61 enable \&add_headers;
7e3d8247 62 enable 'Static', path => qr,^/static/,;
68d5c3ff 63 enable 'Log4perl', category => 'plack';
be1da3f9 64 enable \&add_database;
8d725691
MG
65 enable '+Plack::App::Gruntmaster::Auth',
66 dbi_connect => [$ENV{GRUNTMASTER_DSN} // 'dbi:Pg:', '', ''],
67 realm => 'Gruntmaster 6000',
68 mail_from => $ENV{GRUNTMASTER_RESET_FROM};
594d53ba 69 Plack::App::Gruntmaster->run_if_script
7dc32473 70}
This page took 0.054425 seconds and 4 git commands to generate.