Use a Link: header with the default stylesheet
[plack-app-gruntmaster.git] / app.psgi
index 85e8847a44e8b7420e8cefca46ec862075f06cfe..f7c85ffec3149dbd1bba33486039966bb74dfd92 100644 (file)
--- a/app.psgi
+++ b/app.psgi
@@ -5,11 +5,8 @@ no if $] >= 5.017011, warnings => 'experimental::smartmatch';
 use Gruntmaster::Data;
 use Plack::App::Gruntmaster;
 use Plack::Builder;
-use Plack::Request;
 use Plack::Util;
-use Digest::SHA qw/sha256/;
 use Log::Log4perl;
-use Tie::Hash::Expire;
 
 use constant AUTH_TIMEOUT => 5 * 60;
 use constant ACCESSLOG_FORMAT => 'combined';
@@ -31,17 +28,6 @@ CSP
 
 my $db;
 
-tie my %auth, 'Tie::Hash::Expire', {expire_seconds => AUTH_TIMEOUT};
-
-sub authenticate {
-       my ($user, $pass, $env) = @_;
-       my $key = sha256 "$user:$pass";
-       $env->{'gruntmaster.user'} = $user;
-       return 1 if exists $auth{$key};
-       return unless $db->user($user) && $db->user($user)->check_passphrase($pass);
-       $auth{key} = 1;
-}
-
 sub add_database {
        my $app = $_[0];
        sub {
@@ -58,6 +44,7 @@ sub add_headers {
                my $resp = $app->($_[0]);
                my $hdrs = Plack::Util::headers($resp->[1]);
                $hdrs->set('Content-Security-Policy', CONTENT_SECURITY_POLICY);
+               $hdrs->set('Link', '</static/cyborg.css>; rel=stylesheet') if $hdrs->get('Content-Type') =~ m,^text/html,;
                $hdrs->set('Cache-Control', 'public, max-age=604800') if $_[0]->{PATH_INFO} =~ qr,^/static/,;
                $resp->[1] = $hdrs->headers;
                $resp;
@@ -76,6 +63,9 @@ builder {
        enable 'Static', path => qr,^/static/,;
        enable 'Log4perl', category => 'plack';
        enable \&add_database;
-       enable_if { shift->{HTTP_AUTHORIZATION} } 'Auth::Basic', authenticator => \&authenticate, realm => 'Gruntmaster 6000';
+       enable '+Plack::App::Gruntmaster::Auth',
+         dbi_connect => [$ENV{GRUNTMASTER_DSN} // 'dbi:Pg:', '', ''],
+         realm       => 'Gruntmaster 6000',
+         mail_from   => $ENV{GRUNTMASTER_RESET_FROM};
        Plack::App::Gruntmaster->run_if_script
 }
This page took 0.010677 seconds and 4 git commands to generate.