From 088143b31b9b0a8e92bcb6e7fdfb38b7230f474b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 9 Jan 2020 11:45:14 -0300 Subject: [PATCH] Bug 24384: Add Access-Control-Allow-Origin support to OPAC reports svc This patch makes the opac/svc/report script use output_with_http_headers so it sets the Access-Control-Allow-Origin header. To test: 1. Create a new public report and remember the report id 2. Use your favourite too to fetch the report in JSON by issuing: GET http://localhost:8080/cgi-bin/koha/svc/report?id=1 => FAIL: There is no Access-Control-Allow-Origin header 3. Apply this patch 4. Restart Plack $ sudo koha-plack --restart kohadev 5. Set the AccessControlAllowOrigin to anything (for example, https://koha-community.org) 6. Repeat 2 => SUCCESS: On the response headers you find Access-Control-Allow-Origin: https://koha-community.org 7. Sign off :-D Signed-off-by: David Nind Signed-off-by: Nick Clemens --- opac/svc/report | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/opac/svc/report b/opac/svc/report index dac74277db..ef07334573 100755 --- a/opac/svc/report +++ b/opac/svc/report @@ -23,6 +23,7 @@ use Modern::Perl; +use C4::Output qw(output_with_http_headers); use C4::Reports::Guided; use Koha::Reports; use JSON; @@ -85,8 +86,4 @@ unless ($json_text) { } } -print $query->header( - -charset => 'UTF-8', - -type => 'application/json' -); -print $json_text; +output_with_http_headers( $query, undef, $json_text, 'json'); -- 2.11.0