From 1cd92d1e1210198deede4cd72f4b385da6668e3d Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 25 Apr 2017 19:47:50 +0100 Subject: [PATCH] Added a basic CORS options for api/* --- lib/Pear/LocalLoop.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index b999724..d8231d3 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -112,6 +112,17 @@ sub startup { my $api_public_get = $r->under('/api'); $api_public_get->get('/info/ages')->to('api-info#get_ages'); + $api_public_get->options('*' => sub { + my $self = shift; + + $self->res->headers->header('Access-Control-Allow-Origin'=> 'http://localhost:7000'); + $self->res->headers->header('Access-Control-Allow-Credentials' => 'true'); + $self->res->headers->header('Access-Control-Allow-Methods' => 'GET, OPTIONS, POST, DELETE, PUT'); + $self->res->headers->header('Access-Control-Allow-Headers' => 'Content-Type, X-CSRF-Token'); + $self->res->headers->header('Access-Control-Max-Age' => '1728000'); + + $self->respond_to(any => { data => '', status => 200 }); + }); # Always available api routes my $api_public = $r->under('/api')->to('api-auth#check_json');