Remove some useless things from app.psgi
[plack-app-gruntmaster.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'
17img-src 'self'
18referrer origin-when-cross-origin
19script-src 'self'
20style-src 'self'
21CSP
22 chomp $csp;
23 $csp =~ s/\n/; /gr;
24}
c85bf4a6 25
be1da3f9 26my $db;
5a879d9a 27
be1da3f9
MG
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
3b69df7a
MG
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);
6d4b4529 44 $hdrs->set('Link', '</static/cyborg.css>; rel=stylesheet') if $hdrs->get('Content-Type') =~ m,^text/html,;
3b69df7a
MG
45 $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,;
46 $resp->[1] = $hdrs->headers;
47 $resp;
48 }
49}
50
28b3c465 51Log::Log4perl->init_once('log.conf');
58a0ba09 52$ENV{DBIC_NULLABLE_KEY_NOWARN} = 1;
68d5c3ff 53
7dc32473 54builder {
28aeef34 55 enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }};
287424cb 56 enable 'ContentLength';
3b69df7a 57 enable \&add_headers;
7e3d8247 58 enable 'Static', path => qr,^/static/,;
68d5c3ff 59 enable 'Log4perl', category => 'plack';
be1da3f9 60 enable \&add_database;
8d725691
MG
61 enable '+Plack::App::Gruntmaster::Auth',
62 dbi_connect => [$ENV{GRUNTMASTER_DSN} // 'dbi:Pg:', '', ''],
63 realm => 'Gruntmaster 6000',
64 mail_from => $ENV{GRUNTMASTER_RESET_FROM};
594d53ba 65 Plack::App::Gruntmaster->run_if_script
7dc32473 66}
This page took 0.023122 seconds and 4 git commands to generate.