<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body 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;" class=""><div style="-webkit-user-select: all; -webkit-user-drag: element; display: inline-block;" class="apple-rich-link" draggable="true" role="link" data-url="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing"><a style="border-radius:10px;font-family:-apple-system, Helvetica, Arial, sans-serif;display:block;-webkit-user-select:none;width:300px;user-select:none;-webkit-user-modify:read-only;user-modify:read-only;overflow:hidden;text-decoration:none;" class="lp-rich-link" rel="nofollow" href="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing" dir="ltr" role="button" draggable="false" width="300"><table style="table-layout:fixed;border-collapse:collapse;width:300px;background-color:#E9E9EB;font-family:-apple-system, Helvetica, Arial, sans-serif;" class="lp-rich-link-emailBaseTable" cellpadding="0" cellspacing="0" border="0" width="300"><tbody><tr><td vertical-align="center"><table bgcolor="#E9E9EB" cellpadding="0" cellspacing="0" width="300" style="font-family:-apple-system, Helvetica, Arial, sans-serif;table-layout:fixed;background-color:rgba(233, 233, 235, 1);" class="lp-rich-link-captionBar"><tbody><tr><td style="padding:8px 0px 8px 0px;" class="lp-rich-link-captionBar-textStackItem"><div style="max-width:100%;margin:0px 16px 0px 16px;overflow:hidden;" class="lp-rich-link-captionBar-textStack"><div style="word-wrap:break-word;font-weight:500;font-size:12px;overflow:hidden;text-overflow:ellipsis;text-align:left;" class="lp-rich-link-captionBar-textStack-topCaption-leading"><a rel="nofollow" href="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing" style="text-decoration: none" draggable="false"><font color="#000000" style="color: rgba(0, 0, 0, 1);">Dancer::Plugin::CORS::Sharing</font></a></div><div style="word-wrap:break-word;font-weight:400;font-size:11px;overflow:hidden;text-overflow:ellipsis;text-align:left;" class="lp-rich-link-captionBar-textStack-bottomCaption-leading"><a rel="nofollow" href="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing" style="text-decoration: none" draggable="false"><font color="#A2A2A9" style="color: rgba(60, 60, 67, 0.6);">metacpan.org</font></a></div></div></td><td style="padding:6px 12px 6px 0px;" class="lp-rich-link-captionBar-rightIconItem" width="36"><a rel="nofollow" href="https://metacpan.org/pod/Dancer::Plugin::CORS::Sharing" draggable="false"><img style="pointer-events:none !important;display:inline-block;width:36px;height:36px;border-radius:3px;" width="36" height="36" draggable="false" class="lp-rich-link-captionBar-rightIcon" alt="apple-touch-icon.png" src="cid:B550EC13-F406-42B1-A1E4-02E458C59F7E"></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 &lt;patrice.karatchentzeff@gmail.com&gt; a écrit&nbsp;:<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' =&gt; sub {</span><br><span> &nbsp;my $post = from_json( request-&gt;body );</span><br><span> &nbsp;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>&lt;patrice.karatchentzeff@gmail.com&gt; 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' =&gt; sub {</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;response_header 'Access-Control-Allow-Origin' =&gt; '*';</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' =&gt; sub {</span><br></blockquote><blockquote type="cite"><span> &nbsp;my @data = ( {</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; 1,</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username =&gt; 42,</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name &nbsp;&nbsp;&nbsp;&nbsp;=&gt; 100234,</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;email &nbsp;&nbsp;&nbsp;=&gt; [qw(one two three)],</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; 2,</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username =&gt; "toto",</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name &nbsp;&nbsp;&nbsp;&nbsp;=&gt; "SiSi",</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;email &nbsp;&nbsp;&nbsp;=&gt; [qw(4 5 6)],</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);</span><br></blockquote><blockquote type="cite"><span> &nbsp;send_as JSON =&gt; \@data;</span><br></blockquote><blockquote type="cite"><span> &nbsp;};</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' =&gt; sub {</span><br></blockquote><blockquote type="cite"><span> &nbsp;my $post = from_json( request-&gt;body );</span><br></blockquote><blockquote type="cite"><span> &nbsp;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> &nbsp;&nbsp;&nbsp;enable 'CrossOrigin', origins =&gt; '*';</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;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> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|\ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_,,,---,,_ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Patrice KARATCHENTZEFF</span><br></blockquote><blockquote type="cite"><span>ZZZzz /,`.-'`' &nbsp;&nbsp;&nbsp;-. &nbsp;;-;;,_ &nbsp;&nbsp;mailto:patrice.karatchentzeff@gmail.com</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;&nbsp;|,4- &nbsp;) )-,_. ,\ ( &nbsp;`'-'</span><br></blockquote><blockquote type="cite"><span> &nbsp;&nbsp;&nbsp;'---''(_/--' &nbsp;`-'\_)</span><br></blockquote><span></span><br><span></span><br><span></span><br><span>-- </span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|\ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_,,,---,,_ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Patrice KARATCHENTZEFF</span><br><span>ZZZzz /,`.-'`' &nbsp;&nbsp;&nbsp;-. &nbsp;;-;;,_ &nbsp;&nbsp;mailto:patrice.karatchentzeff@gmail.com</span><br><span> &nbsp;&nbsp;&nbsp;&nbsp;|,4- &nbsp;) )-,_. ,\ ( &nbsp;`'-'</span><br><span> &nbsp;&nbsp;&nbsp;'---''(_/--' &nbsp;`-'\_)</span><br><span>_______________________________________________</span><br><span>Perl mailing list</span><br><span>Perl@mongueurs.net</span><br><span>http://listes.mongueurs.net/mailman/listinfo/perl</span><br><span>Attention, les archives sont publiques</span><br></div></blockquote></div></body></html>