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