]> iEval git - gruntmaster-page.git/blob - app.psgi
Remove access logging
[gruntmaster-page.git] / app.psgi
1 #!/usr/bin/perl -w
2 use v5.14;
3 no if $] >= 5.017011, warnings => 'experimental::smartmatch';
4
5 use Gruntmaster::Data;
6 use Plack::App::Gruntmaster;
7 use Plack::Builder;
8 use Plack::Util;
9 use Log::Log4perl;
10
11 use constant AUTH_TIMEOUT => 5 * 60;
12
13 sub CONTENT_SECURITY_POLICY () {
14 my $csp = <<CSP;
15 default-src 'none'
16 connect-src 'self'
17 form-action 'self'
18 frame-ancestors 'none'
19 img-src 'self'
20 referrer origin-when-cross-origin
21 script-src 'self'
22 style-src 'self'
23 CSP
24 chomp $csp;
25 $csp =~ s/\n/; /gr;
26 }
27
28 my $db;
29
30 sub add_database {
31 my $app = $_[0];
32 sub {
33 my ($env) = @_;
34 $db //= Gruntmaster::Data->connect($ENV{GRUNTMASTER_DSN} // 'dbi:Pg:');
35 $env->{'gruntmaster.dbic'} = $db;
36 $app->($env)
37 }
38 }
39
40 sub add_headers {
41 my $app = $_[0];
42 sub {
43 my $resp = $app->($_[0]);
44 my $hdrs = Plack::Util::headers($resp->[1]);
45 $hdrs->set('Content-Security-Policy', CONTENT_SECURITY_POLICY);
46 $hdrs->set('Link', '</static/cyborg.css>; rel=stylesheet') if $hdrs->get('Content-Type') =~ m,^text/html,;
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
53 Log::Log4perl->init_once('log.conf');
54 $ENV{DBIC_NULLABLE_KEY_NOWARN} = 1;
55
56 builder {
57 enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }};
58 enable 'ContentLength';
59 enable \&add_headers;
60 enable 'Static', path => qr,^/static/,;
61 enable 'Log4perl', category => 'plack';
62 enable \&add_database;
63 enable '+Plack::App::Gruntmaster::Auth',
64 dbi_connect => [$ENV{GRUNTMASTER_DSN} // 'dbi:Pg:', '', ''],
65 realm => 'Gruntmaster 6000',
66 mail_from => $ENV{GRUNTMASTER_RESET_FROM};
67 Plack::App::Gruntmaster->run_if_script
68 }
This page took 0.05542 seconds and 4 git commands to generate.