]> iEval git - gruntmaster-page.git/blame_incremental - app.psgi
Do not handle static files (nginx does this already)
[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;
12
13sub CONTENT_SECURITY_POLICY () {
14 my $csp = <<CSP;
15default-src 'none'
16connect-src 'self'
17form-action 'self'
18frame-ancestors 'none'
19img-src 'self' https://static.mindcoding.ro
20referrer origin-when-cross-origin
21script-src https://static.mindcoding.ro/static/js.js
22style-src https://static.mindcoding.ro/static/css/
23CSP
24 chomp $csp;
25 $csp =~ s/\n/; /gr;
26}
27
28my $db;
29
30sub 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
40sub 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', '<https://static.mindcoding.ro/static/slate.css>; rel=stylesheet') if $hdrs->get('Content-Type') =~ m,^text/html,;
47 $resp->[1] = $hdrs->headers;
48 $resp;
49 }
50}
51
52Log::Log4perl->init_once('log.conf');
53$ENV{DBIC_NULLABLE_KEY_NOWARN} = 1;
54
55builder {
56 enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }};
57 enable 'ContentLength';
58 enable \&add_headers;
59 enable 'Log4perl', category => 'plack';
60 enable \&add_database;
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};
65 Plack::App::Gruntmaster->run_if_script
66}
This page took 0.020356 seconds and 4 git commands to generate.