From 4c432cbe8fa1c64d2d442455ee41e4a163538446 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 4 Aug 2016 11:47:16 -0300 Subject: [PATCH] Bug 17030: Make REST api available on packages with plack enabled This patch is the starting point for making the REST api available on Plack. What it does: - It creates the /api/v1/app.pl mount point in plack.psgi - It enables the ProxyPass and ProxyPassReverse directives so it is reached through Plack. TODO: It is missing the rewrite part. To test: - Grab the following files, and put them in /etc/koha (overwrite the existing ones) debian/templates/apache-shared-intranet-plack.conf debian/templates/apache-shared-opac-plack.conf - Tweak your /etc/koha/sites/kohadev/plack.psgi file so the API-related stuff is present on your file. - Make sure Plack is enabled for the instance: $ sudo koha-plack --enable kohadev $ sudo koha-plack --restart kohadev $ sudo service apache2 restart - Follow the previous patch test plan, but use this URLs (no pretty URL for now): http://localhost:8080/api/v1/app.pl/api/v1/patrons/50 http://localhost:8081/api/v1/app.pl/api/v1/patrons/50 => SUCCESS: You get a JSON response from the API [1] - Sign off :-D Note: this patch made a bug visible (the session is lost when accessing the API through Plack) but it shouldn't prevent its inclusion because the API right now is not even available as default for developers to test or fix it. --- debian/templates/apache-shared-intranet-plack.conf | 4 ++-- debian/templates/apache-shared-opac-plack.conf | 4 ++-- debian/templates/plack.psgi | 16 ++++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/debian/templates/apache-shared-intranet-plack.conf b/debian/templates/apache-shared-intranet-plack.conf index 91e47f6..b544958 100644 --- a/debian/templates/apache-shared-intranet-plack.conf +++ b/debian/templates/apache-shared-intranet-plack.conf @@ -28,8 +28,8 @@ ProxyPassReverse /cgi-bin/koha "unix:/var/run/koha/${instance}/plack.sock|http://localhost/intranet" # Point the /api endpoint to Plack - # ProxyPass /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" - # ProxyPassReverse /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" + ProxyPass /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" + ProxyPassReverse /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" diff --git a/debian/templates/apache-shared-opac-plack.conf b/debian/templates/apache-shared-opac-plack.conf index 95787d8..6a4b3b0 100644 --- a/debian/templates/apache-shared-opac-plack.conf +++ b/debian/templates/apache-shared-opac-plack.conf @@ -18,8 +18,8 @@ ProxyPassReverse /cgi-bin/koha "unix:/var/run/koha/${instance}/plack.sock|http://localhost/opac" # Point the /api endpoint to Plack - # ProxyPass /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" - # ProxyPassReverse /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" + ProxyPass /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" + ProxyPassReverse /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" diff --git a/debian/templates/plack.psgi b/debian/templates/plack.psgi index 704b91b..397998f 100644 --- a/debian/templates/plack.psgi +++ b/debian/templates/plack.psgi @@ -25,6 +25,8 @@ use Plack::App::CGIBin; use Plack::App::Directory; use Plack::App::URLMap; +use Mojo::Server::PSGI; + # Pre-load libraries use C4::Boolean; use C4::Branch; @@ -60,16 +62,18 @@ my $opac = Plack::App::CGIBin->new( root => '/usr/share/koha/opac/cgi-bin/opac' )->to_app; -# my $api = Plack::App::CGIBin->new( -# root => '/usr/share/koha/api/' -# )->to_app; +my $apiv1 = builder { + my $server = Mojo::Server::PSGI->new; + $server->load_app('/usr/share/koha/api/v1/app.pl'); + $server->to_psgi_app; +}; builder { enable "ReverseProxy"; enable "Plack::Middleware::Static"; - mount '/opac' => $opac; - mount '/intranet' => $intranet; - # mount '/api' => $api; + mount '/opac' => $opac; + mount '/intranet' => $intranet; + mount '/api/v1/app.pl' => $apiv1; }; -- 2.9.2