From 423e353eb9acb2423237d0974d7f042903dd034d Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Mon, 3 Aug 2015 17:54:51 +0300 Subject: [PATCH] Bug 14747: RESTful API with reverse proxy configuration OPTIONAL replacement to the Bug 13799: RESTful API with Mojolicious and Swagger2 httpd-configuration. Instead of having to go to your dns-provider, you can run the api from your current virtualhost. Use these configurations to reverse proxy www.host.domain/v1/ to the REST API. --------------------------- :INSTALLATION INSTRUCTIONS: --------------------------- You need Bug 14448: Adding the REST API as a Hypnotoad service, koha-api-daemon. to deploy the backend Mojolicous application as a FastCGI-daemon. Then add the modifications from etc/koha-httpd.conf to your /etc/apache2/sites-enabled/koha.conf and adjust paths to fit. ..$ a2enmod proxy ..$ a2enmod proxy_http ..$ service apache2 restart Much recommended is Bug 14458: Add SwaggerUI documentation for RESTful API to browse your API capabilities. Then just go to /v1/doc to see the API autodocumentation. --- etc/koha-httpd.conf | 80 ++++++++++++++++------------------------------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/etc/koha-httpd.conf b/etc/koha-httpd.conf index 4f1fc47..98ab216 100644 --- a/etc/koha-httpd.conf +++ b/etc/koha-httpd.conf @@ -27,6 +27,18 @@ # OVERRIDE_SYSPREF_NAMES for your staff intranet vhost # SetEnv OVERRIDE_SYSPREF_PrefName Value + ##REVERSE PROXY REQUESTS TO THE KOHA API DAEMON + Alias /v1/doc __INTRANET_CGI_DIR__/api/v1/doc + Alias /v1/swagger.json "__INTRANET_CGI_DIR__/api/v1/swagger.json" + + ProxyRequests Off #Disable anonymous forward proxying + ProxyPreserveHost On + ProxyPass /v1/doc ! + ProxyPass /v1/swagger.json ! + ProxyPass /v1/ http://localhost:8081/v1/ keepalive=On + ProxyPassReverse /v1/ http://localhost:8081/v1/ + ##REVERSE PROXYING OK + Options -Indexes @@ -112,20 +124,6 @@ RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/opac-detail\.pl?bib=$1 [PT] RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT] RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT] - - # REST API configuration - Alias "/api" "__OPAC_CGI_DIR__/api" - - Options +ExecCGI +FollowSymlinks - AddHandler cgi-script .pl - - RewriteEngine On - RewriteBase /api/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{DOCUMENT_ROOT}/../api/$1/app.pl -f - RewriteRule ^(.*?)/.* $1/app.pl/api/$0 [L] - @@ -158,6 +156,18 @@ ErrorDocument 404 /cgi-bin/koha/errors/404.pl ErrorDocument 500 /cgi-bin/koha/errors/500.pl + ##REVERSE PROXY REQUESTS TO THE KOHA API DAEMON + Alias /v1/doc __INTRANET_CGI_DIR__/api/v1/doc + Alias /v1/swagger.json "__INTRANET_CGI_DIR__/api/v1/swagger.json" + + ProxyRequests Off #Disable anonymous forward proxying + ProxyPreserveHost On + ProxyPass /v1/doc ! + ProxyPass /v1/swagger.json ! + ProxyPass /v1/ http://localhost:8081/v1/ keepalive=On + ProxyPassReverse /v1/ http://localhost:8081/v1/ + ##REVERSE PROXYING OK + Options -Indexes @@ -228,47 +238,5 @@ RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/detail\.pl?bib=$1 [PT] RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT] RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT] - - - # REST API configuration - Alias "/api" "__INTRANET_CGI_DIR__/api" - - Options +ExecCGI +FollowSymlinks - AddHandler cgi-script .pl - - RewriteEngine On - RewriteBase /api/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{DOCUMENT_ROOT}/../api/$1/app.pl -f - RewriteRule ^(.*?)/.* $1/app.pl/api/$0 [L] - - -# Uncomment this VirtualHost to enable API access through -# api.__WEBSERVER_HOST__:__WEBSERVER_PORT__ -# -# ServerAdmin __WEBMASTER_EMAIL__ -# DocumentRoot __INTRANET_CGI_DIR__/api -# ServerName api.__WEBSERVER_HOST__:__WEBSERVER_PORT__ -# SetEnv KOHA_CONF "__KOHA_CONF_DIR__/koha-conf.xml" -# SetEnv PERL5LIB "__PERL_MODULE_DIR__" -# ErrorLog __LOG_DIR__/koha-api-error_log -# -# -# -# Options +ExecCGI +FollowSymlinks -# AddHandler cgi-script .pl -# -# RewriteEngine on -# -# RewriteRule ^api/(.*) $1 [L] -# -# RewriteCond %{REQUEST_FILENAME} !-f -# RewriteCond %{REQUEST_FILENAME} !-d -# RewriteCond %{DOCUMENT_ROOT}/$1/app.pl -f -# RewriteRule ^(.*?)/.* $1/app.pl/api/$0 [L] -# -# -# -- 1.9.1