Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Plack scaffolding and middleware

  • Loading branch information...
commit e382258f675f7c21a673bb342a7f601929529527 1 parent d1fe6d4
@ctfliblime ctfliblime authored
View
20 C4/Plack/Localize.pm
@@ -0,0 +1,20 @@
+package C4::Plack::Localize;
+use parent qw(Plack::Middleware);
+use Modern::Perl;
+use Plack::Util;
+
+use C4::Context;
+
+use Data::Dumper;
+
+sub call {
+ my ($self, $env) = @_;
+
+ local $C4::Context::context;
+ $C4::Context::context = C4::Context->new();
+
+ my $res = $self->app->($env);
+ return $res;
+}
+
+1;
View
31 C4/Plack/Rewrite.pm
@@ -0,0 +1,31 @@
+package C4::Plack::Rewrite;
+use parent qw(Plack::Middleware);
+
+use Modern::Perl;
+use Plack::Util;
+
+sub _is_staff {
+ my $env = shift;
+
+ my ($hostname) = split(/, /, $env->{HTTP_X_FORWARDED_HOST}//$env->{HTTP_HOST});
+ $hostname //= $env->{SERVER_NAME};
+
+ return $hostname =~ /-staff\./;
+}
+
+sub call {
+ my ($self, $env) = @_;
+
+ if ($env->{REQUEST_URI} ~~ '/') {
+ map {$env->{$_} = _is_staff($env) ? '/mainpage.pl' : '/opac/opac-main.pl'} qw{REQUEST_URI PATH_INFO};
+ }
+ else {
+ my $prepend = (_is_staff($env)) ? '' : '/opac';
+ map {$env->{$_} =~ s{^/cgi-bin/koha(.*)}{$prepend$1}} qw(REQUEST_URI PATH_INFO);
+ }
+
+ my $res = $self->app->($env);
+ return $res;
+}
+
+1;
View
16 C4/Plack/ScrubStatus.pm
@@ -0,0 +1,16 @@
+package C4::Plack::ScrubStatus;
+use parent qw(Plack::Middleware);
+
+use Modern::Perl;
+use Plack::Util;
+
+sub call {
+ my ($self, $env) = @_;
+
+ my $res = $self->app->($env);
+ Plack::Util::header_remove($res->[1], 'Status');
+
+ return $res;
+}
+
+1;
View
25 app.psgi
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+
+use Modern::Perl;
+use Plack::App::CGIBin;
+use Plack::Builder;
+use Data::Dumper;
+
+my $app = Plack::App::CGIBin->new(root => $ENV{PERL5LIB})->to_app;
+
+my $svc = sub {
+ my $env = shift;
+ return [200, [ 'Content-type' => 'text/plain' ], [Dumper [$env, \%ENV]] ];
+};
+
+builder {
+ enable 'Deflater';
+ enable 'Static', path => qr{^/opac-tmpl/}, root => 'koha-tmpl/';
+ enable 'Static', path => qr{^/intranet-tmpl/}, root => 'koha-tmpl/';
+ enable '+C4::Plack::Localize';
+ enable '+C4::Plack::Rewrite';
+ enable '+C4::Plack::ScrubStatus';
+
+ mount '/' => $app;
+ mount '/svc2' => $svc;
+};
View
32 plack-apache.conf
@@ -0,0 +1,32 @@
+FastCgiExternalServer /home/ctftest2/koha-plack.psgi -host 127.0.0.1:5000
+
+<VirtualHost *:80>
+ ServerName ctftest2-plack.sandbox.kohalibrary.com
+ ErrorLog /var/log/apache2/ctftest2-opac-error.log
+ TransferLog /var/log/apache2/ctftest2-opac-access.log
+ DocumentRoot /home/ctftest2/kohaclone/koha-tmpl
+
+ RewriteEngine On
+ RewriteCond %{REQUEST_URI} !^/cgi-bin/koha/opac/
+ RewriteRule ^/cgi-bin/koha/(.*) /cgi-bin/koha/opac/$1 [P]
+
+ RewriteRule ^/$ /cgi-bin/koha/opac/opac-main.pl [P]
+
+ #ProxyPass /cgi-bin/koha/ http://localhost:5000/ # can use this instead of FCGI
+ Alias /cgi-bin/koha/ /home/ctftest2/koha-plack.psgi/
+</VirtualHost>
+
+<VirtualHost *:80>
+ ServerName ctftest2-plack-staff.sandbox.kohalibrary.com
+ ErrorLog /var/log/apache2/ctftest2-staff-error.log
+ TransferLog /var/log/apache2/ctftest2-staff-access.log
+ DocumentRoot /home/ctftest2/kohaclone/koha-tmpl
+
+ RewriteEngine On
+ RewriteRule ^/$ /cgi-bin/koha/mainpage.pl [P]
+ RewriteRule ^/mainpage.pl$ /cgi-bin/koha/mainpage.pl [P]
+
+ #ProxyPass /cgi-bin/koha/ http://localhost:5000/ # can use this instead of FCGI
+ Alias /cgi-bin/koha/ /home/ctftest2/koha-plack.psgi/
+</VirtualHost>
+
Please sign in to comment.
Something went wrong with that request. Please try again.