Skip to content

Commit

Permalink
Re-vamp app.psgi with more specific mounts; deprecate Koha::Plack::Re…
Browse files Browse the repository at this point in the history
…write
  • Loading branch information
ctfliblime committed Aug 15, 2011
1 parent 48082fe commit 3d63f5c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 38 deletions.
33 changes: 0 additions & 33 deletions Koha/Plack/Rewrite.pm

This file was deleted.

27 changes: 22 additions & 5 deletions app.psgi
Expand Up @@ -5,26 +5,43 @@ use Plack::App::CGIBin;
use Plack::Builder;
use Koha::Plack::Util;

my $root = $ENV{PERL5LIB};
my $app = Plack::App::CGIBin->new(root => $root)->to_app;
my $root = $ENV{KOHA_BASE} // '.';

my $main_app = Plack::App::CGIBin->new(root => $root)->to_app;
my $svc_app = Plack::App::CGIBin->new(root => "$root/svc", exec_cb => sub{1})->to_app;

use Koha::Squatting::Reserve 'On::PSGI';
use Koha::Squatting::Branch 'On::PSGI';
my $reserves = Koha::Squatting::Reserve->init;
my $branches = Koha::Squatting::Branch->init;

sub is_staff {
my $hostname = Koha::Plack::Util::GetCanonicalHostname(shift);
return $hostname =~ /-staff\./;
}

builder {
enable 'Deflater';
enable 'HTTPExceptions';
enable 'MethodOverride';
enable 'Status', path => qr{/C4/|/Koha/|/misc/|/t/|/xt/|/etc/}, status => 404;

enable 'Static', path => qr{^/opac-tmpl/}, root => "$root/koha-tmpl/";
enable 'Static', path => qr{^/intranet-tmpl/}, root => "$root/koha-tmpl/";

enable 'Status', path => qr{/C4/|/Koha/|/misc/|/t/|/xt/|/etc/}, status => 404;
enable 'Rewrite', rules => sub {
my $env = shift;
return 302 if (is_staff($env) && s{^/$}{/cgi-bin/koha/mainpage.pl});
return 302 if (!is_staff($env) && s{^/$}{/cgi-bin/koha/opac-main.pl});
if (!is_staff($env)) { s{^/cgi-bin/koha/}{/cgi-bin/koha/opac/}}
return;
};
enable 'Header', unset => ['Status'];
enable '+Koha::Plack::Localize';
enable '+Koha::Plack::Rewrite';
mount '/branches/' => sub {Koha::Squatting::Branch->psgi(shift)};
mount '/reserves/' => sub {Koha::Squatting::Reserve->psgi(shift)};
mount '/' => $app;
mount '/cgi-bin/koha/' => $main_app;
mount '/svc/' => $svc_app;
};

0 comments on commit 3d63f5c

Please sign in to comment.