<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Merci. Je l'avais vu, mais comme il est taggué Dancer et non Dancer2, je pense qu'il ne conviendra pas.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Merci</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">PK<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le lun. 5 juin 2023 à 13:57, Sébastien Feugère <<a href="mailto:sebastien@feugere.net">sebastien@feugere.net</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Il faudra sûrement résoudre le problème à la base pour passer le site en production. Je recommanderais l’utilisation d’un plug-in Dancer qui permet d’activer CORS sur toutes les routes souhaitées:<div><br></div><div><div style="display:block"><div style="display:inline-block" role="link"><a style="border-radius:10px;font-family:-apple-system,Helvetica,Arial,sans-serif;display:block;width:300px;overflow:hidden;text-decoration:none" rel="nofollow" href="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing" dir="ltr" role="button" width="300" target="_blank"><table style="table-layout:fixed;border-collapse:collapse;width:300px;background-color:rgb(233,233,235);font-family:-apple-system,Helvetica,Arial,sans-serif" width="300" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td><table style="font-family:-apple-system,Helvetica,Arial,sans-serif;table-layout:fixed;background-color:rgb(233,233,235)" width="300" cellspacing="0" cellpadding="0" bgcolor="#E9E9EB"><tbody><tr><td style="padding:8px 0px"><div style="max-width:100%;margin:0px 16px;overflow:hidden"><div style="font-weight:500;font-size:12px;overflow:hidden;text-overflow:ellipsis;text-align:left"><a rel="nofollow" href="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing" style="text-decoration:none" target="_blank"><font style="color:rgb(0,0,0)" color="#000000">Dancer::Plugin::CORS::Sharing</font></a></div><div style="font-weight:400;font-size:11px;overflow:hidden;text-overflow:ellipsis;text-align:left"><a rel="nofollow" href="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing" style="text-decoration:none" target="_blank"><font style="color:rgba(60,60,67,0.6)" color="#A2A2A9">metacpan.org</font></a></div></div></td><td style="padding:6px 12px 6px 0px" width="36"><a rel="nofollow" href="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing" target="_blank"><img style="display: inline-block; width: 36px; height: 36px; border-radius: 3px;" alt="apple-touch-icon.png" src="cid:1888cb7f7e18e3918d51" width="36" height="36"></a></td></tr></tbody></table></td></tr></tbody></table></a></div></div><br><br><div dir="ltr">Sébastien Feugère</div><div dir="ltr"><br><blockquote type="cite">Le 5 juin 2023 à 13:44, Patrice Karatchentzeff <<a href="mailto:patrice.karatchentzeff@gmail.com" target="_blank">patrice.karatchentzeff@gmail.com</a>> a écrit :<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><span>Bon, j'ai viré le problème en réussissant à désactiver CORS dans la</span><br><span>requête de départ en javascript. Mais le problème demeure...</span><br><span></span><br><span>Et j'avais une erreur stupide :</span><br><span></span><br><span>get '/login' => sub {</span><br><span> my $post = from_json( request->body );</span><br><span> print $post;</span><br><span>};</span><br><span></span><br><span>C'est un post et pas un get :(</span><br><span></span><br><span>PK</span><br><span></span><br><span>Le lun. 5 juin 2023 à 09:52, Patrice Karatchentzeff</span><br><span><<a href="mailto:patrice.karatchentzeff@gmail.com" target="_blank">patrice.karatchentzeff@gmail.com</a>> a écrit :</span><br><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Salut,</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>J'ai un truc bizarre avec Dancer2. J'ai besoin d'autoriser CORS et</span><br></blockquote><blockquote type="cite"><span>pour le dév, je le mets à tout le monde (*) pour ne pas me prendre la</span><br></blockquote><blockquote type="cite"><span>tête. Dancer2 est pour le back-end et j'ai un front-end en javascript</span><br></blockquote><blockquote type="cite"><span>(React Native)/</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Le plus simple est de faire un hook avant une route :</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>hook 'before' => sub {</span><br></blockquote><blockquote type="cite"><span> response_header 'Access-Control-Allow-Origin' => '*';</span><br></blockquote><blockquote type="cite"><span>};</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Si je veux lire un JSON sur le serveur (GET), ça fonctionne.</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>get '/message' => sub {</span><br></blockquote><blockquote type="cite"><span> my @data = ( {</span><br></blockquote><blockquote type="cite"><span> id => 1,</span><br></blockquote><blockquote type="cite"><span> username => 42,</span><br></blockquote><blockquote type="cite"><span> name => 100234,</span><br></blockquote><blockquote type="cite"><span> email => [qw(one two three)],</span><br></blockquote><blockquote type="cite"><span> },</span><br></blockquote><blockquote type="cite"><span> {</span><br></blockquote><blockquote type="cite"><span> id => 2,</span><br></blockquote><blockquote type="cite"><span> username => "toto",</span><br></blockquote><blockquote type="cite"><span> name => "SiSi",</span><br></blockquote><blockquote type="cite"><span> email => [qw(4 5 6)],</span><br></blockquote><blockquote type="cite"><span> },</span><br></blockquote><blockquote type="cite"><span> );</span><br></blockquote><blockquote type="cite"><span> send_as JSON => \@data;</span><br></blockquote><blockquote type="cite"><span> };</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Si je veux en envoyer un (POST), le débogueur m'indique que la requête</span><br></blockquote><blockquote type="cite"><span>est interdite, parce que CORS n'est pas actif !</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>get '/login' => sub {</span><br></blockquote><blockquote type="cite"><span> my $post = from_json( request->body );</span><br></blockquote><blockquote type="cite"><span> print $post;</span><br></blockquote><blockquote type="cite"><span>};</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>J'ai essayé de généraliser avec Plack :</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>use Plack::Builder;</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>builder {</span><br></blockquote><blockquote type="cite"><span> enable 'CrossOrigin', origins => '*';</span><br></blockquote><blockquote type="cite"><span> dance;</span><br></blockquote><blockquote type="cite"><span>};</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Mais ça ne fonctionne pas mieux :(</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Est-ce que vous avez une piste pour me dépanner ?</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>Merci</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>PK</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>--</span><br></blockquote><blockquote type="cite"><span> |\ _,,,---,,_ Patrice KARATCHENTZEFF</span><br></blockquote><blockquote type="cite"><span>ZZZzz /,`.-'`' -. ;-;;,_ mailto:<a href="mailto:patrice.karatchentzeff@gmail.com" target="_blank">patrice.karatchentzeff@gmail.com</a></span><br></blockquote><blockquote type="cite"><span> |,4- ) )-,_. ,\ ( `'-'</span><br></blockquote><blockquote type="cite"><span> '---''(_/--' `-'\_)</span><br></blockquote><span></span><br><span></span><br><span></span><br><span>-- </span><br><span> |\ _,,,---,,_ Patrice KARATCHENTZEFF</span><br><span>ZZZzz /,`.-'`' -. ;-;;,_ mailto:<a href="mailto:patrice.karatchentzeff@gmail.com" target="_blank">patrice.karatchentzeff@gmail.com</a></span><br><span> |,4- ) )-,_. ,\ ( `'-'</span><br><span> '---''(_/--' `-'\_)</span><br><span>_______________________________________________</span><br><span>Perl mailing list</span><br><span><a href="mailto:Perl@mongueurs.net" target="_blank">Perl@mongueurs.net</a></span><br><span><a href="http://listes.mongueurs.net/mailman/listinfo/perl" target="_blank">http://listes.mongueurs.net/mailman/listinfo/perl</a></span><br><span>Attention, les archives sont publiques</span><br></div></blockquote></div></div>_______________________________________________<br>
Perl mailing list<br>
<a href="mailto:Perl@mongueurs.net" target="_blank">Perl@mongueurs.net</a><br>
<a href="http://listes.mongueurs.net/mailman/listinfo/perl" rel="noreferrer" target="_blank">http://listes.mongueurs.net/mailman/listinfo/perl</a><br>
Attention, les archives sont publiques</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div> |\ _,,,---,,_ Patrice KARATCHENTZEFF<br>ZZZzz /,`.-'`' -. ;-;;,_ mailto:<a href="mailto:patrice.karatchentzeff@gmail.com" target="_blank">patrice.karatchentzeff@gmail.com</a><br> |,4- ) )-,_. ,\ ( `'-' <br> '---''(_/--' `-'\_) <br></div></div></div></div></div>