]> iEval git - gruntmaster-page.git/blame_incremental - app.psgi
Display format extension instead of format in job list
[gruntmaster-page.git] / app.psgi
... / ...
CommitLineData
1#!/usr/bin/perl -w
2use v5.14;
3no if $] >= 5.017011, warnings => 'experimental::smartmatch';
4
5use Gruntmaster::Data;
6use Plack::App::Gruntmaster;
7use Plack::Builder;
8use Plack::Util;
9use Log::Log4perl;
10
11use constant AUTH_TIMEOUT => 5 * 60;
12use constant ACCESSLOG_FORMAT => 'combined';
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}
28
29my $db;
30
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
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('Link', '</static/cyborg.css>; rel=stylesheet') if $hdrs->get('Content-Type') =~ m,^text/html,;
48 $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,;
49 $resp->[1] = $hdrs->headers;
50 $resp;
51 }
52}
53
54Log::Log4perl->init_once('log.conf');
55my $access_logger = Log::Log4perl->get_logger('access');
56$ENV{DBIC_NULLABLE_KEY_NOWARN} = 1;
57
58builder {
59 enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }};
60 enable 'AccessLog', format => ACCESSLOG_FORMAT, logger => sub { $access_logger->info(@_) };
61 enable 'ContentLength';
62 enable \&add_headers;
63 enable 'Static', path => qr,^/static/,;
64 enable 'Log4perl', category => 'plack';
65 enable \&add_database;
66 enable '+Plack::App::Gruntmaster::Auth',
67 dbi_connect => [$ENV{GRUNTMASTER_DSN} // 'dbi:Pg:', '', ''],
68 realm => 'Gruntmaster 6000',
69 mail_from => $ENV{GRUNTMASTER_RESET_FROM};
70 Plack::App::Gruntmaster->run_if_script
71}
This page took 0.027026 seconds and 4 git commands to generate.