Bug 20134: Remove /api/v1/app.pl from the generated URLs

This patch removes the /api/v1/app.pl prefix from generated baseUrl.
It has the consequence of hardcoding / as the base path for the API.

This is ok because we don't currently support mounting Koha pieces in
different than hardcoded paths (/cgi-bin/koha?), but certainly worth
mentioning because this will need to depend on a syspref or config entry
when someone chages this behviour.

To test:
- On master, point your browser to:
  http://kohadev.mydnsname.org:8080/api/v1/
=> FAIL: basePath looks like /api/v1/app.pl/api/v1
- Apply this patch
- Restart memcached and plack:
  $ restart_all
or
  $ sudo systemctl restart memcached && sudo systemctl restart
  koha-common
- Reload http://kohadev.mydnsname.org:8080/api/v1/
=> SUCCESS: basePath is /api/v1
- Sign off :-D

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
This commit is contained in:
Tomas Cohen Arazi 2018-02-05 10:28:37 -03:00 committed by Jonathan Druart
parent bb98e99dc6
commit d77d371c4f
1 changed files with 5 additions and 0 deletions

View File

@ -38,6 +38,11 @@ Overloaded Mojolicious->startup method. It is called at application startup.
sub startup {
my $self = shift;
# Remove /api/v1/app.pl/ from the path
$self->hook( before_dispatch => sub {
shift->req->url->base->path('/');
});
# Force charset=utf8 in Content-Type header for JSON responses
$self->types->type(json => 'application/json; charset=utf8');