Bugzilla – Attachment 54013 Details for
Bug 17030
Configure the REST api on packages install
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17030: Make REST api available on packages with plack enabled
Bug-17030-Make-REST-api-available-on-packages-with.patch (text/plain), 4.89 KB, created by
Benjamin Rokseth
on 2016-08-04 21:27:36 UTC
(
hide
)
Description:
Bug 17030: Make REST api available on packages with plack enabled
Filename:
MIME Type:
Creator:
Benjamin Rokseth
Created:
2016-08-04 21:27:36 UTC
Size:
4.89 KB
patch
obsolete
>From a0c46b2d23439f38bba3d059764954ad63440436 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >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. >- It sets rewrite rules so we can use the 'pretty' urls (i.e. > /api/v1/patrons instead of /api/v1/app.pl/api/v1/patrons). > >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): > > 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] >- Not use this URLs: > http://localhost:8080/api/v1/patrons/50 > http://localhost:8081/api/v1/patrons/50 >=> SUCCESS: You get a JSON response from the API [1] >- Sign off :-D > >[1] 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. > >Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no> >--- > debian/templates/apache-shared-intranet-plack.conf | 7 +++++-- > debian/templates/apache-shared-opac-plack.conf | 7 +++++-- > debian/templates/plack.psgi | 16 ++++++++++------ > 3 files changed, 20 insertions(+), 10 deletions(-) > >diff --git a/debian/templates/apache-shared-intranet-plack.conf b/debian/templates/apache-shared-intranet-plack.conf >index 91e47f6..f77f640 100644 >--- a/debian/templates/apache-shared-intranet-plack.conf >+++ b/debian/templates/apache-shared-intranet-plack.conf >@@ -28,8 +28,11 @@ > 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" >+ RewriteCond %{REQUEST_URI} !^/api/v[0-1]+/app.pl >+ RewriteRule ^/api/(v[0-9]+)/(.*)$ /api/$1/app.pl/api/$1/$2 [L,PT] >+ >+ ProxyPass /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" >+ ProxyPassReverse /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" > > </IfModule> > </IfVersion> >diff --git a/debian/templates/apache-shared-opac-plack.conf b/debian/templates/apache-shared-opac-plack.conf >index 95787d8..f68e3d2 100644 >--- a/debian/templates/apache-shared-opac-plack.conf >+++ b/debian/templates/apache-shared-opac-plack.conf >@@ -18,8 +18,11 @@ > 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" >+ RewriteCond %{REQUEST_URI} !^/api/v[0-1]+/app.pl >+ RewriteRule ^/api/(v[0-9]+)/(.*)$ /api/$1/app.pl/api/$1/$2 [L,PT] >+ >+ ProxyPass /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" >+ ProxyPassReverse /api "unix:/var/run/koha/${instance}/plack.sock|http://localhost/api" > > </IfModule> > </IfVersion> >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.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17030
:
53991
|
53992
|
53995
|
54008
|
54012
|
54013
|
54049
|
54050