All,

Thanks for all your help. We appear to have overcome the CORS hurdle and 
have something that at least is not giving a CORS error in Firefox which is 
more than we have had in the last 48 hours.

It turns out that you do need to send 'Access-Control-Allow-Origin' => '*' 
with the POST reply. It also turns out that a lot of the headers I was 
sending were not needed.

For posterity and because somebody else might find it useful, here is the 
full source code (that sounds rather grand for a hack), that works for us. 
It does nothing useful expect not throw an error.

#!/usr/bin/perl -w

use Mojolicious::Lite;

options '*' => sub {
    my $self = shift;

    $self->res->headers->header('Access-Control-Allow-Origin' => '*');
    #$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');
    #$self->res->headers->header('Access-Control-Max-Age' => '1728000');

    $self->respond_to(any => { data => '', status => 200 });
};

get '/data' => sub {
    my $self = shift;

    print "GET found\n";
    $self->render(text => 'ok');
};

post '/data' => sub {
    my $self = shift;

    print "\nPOST 3 found\n";
    $self->render(text => 'POST ok' );
};

app->hook(after_dispatch => sub {
    my $c = shift;
    $c->res->headers->header('Access-Control-Allow-Origin' => '*');
          });

app->secrets(['My very secret passphrase.']);

app->start;

Note the commented lines in the options section. We've left them in as they 
may become useful. This is something we can build on, we wrote an awful lot 
of JavaScript which now needs converting to Perl.

Thanks again for all the help, hopefully I can do the same back some day.

Best wishes,

Rob.

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to