Bug 24384: Add Access-Control-Allow-Origin support to OPAC reports svc
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 9 Jan 2020 14:45:14 +0000 (11:45 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 19 Mar 2020 09:23:13 +0000 (09:23 +0000)
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 <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

opac/svc/report

index dac7427..ef07334 100755 (executable)
@@ -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');