@@ -, +, @@ enabled - 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). - 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 - Not use this URLs: http://localhost:8080/api/v1/patrons/50 http://localhost:8081/api/v1/patrons/50 - Sign off :-D --- 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(-) --- a/debian/templates/apache-shared-intranet-plack.conf +++ a/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" --- a/debian/templates/apache-shared-opac-plack.conf +++ a/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" --- a/debian/templates/plack.psgi +++ a/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; }; --