davide-casiraghi / ci-global-calendar

Global Contact Improvisation Calendar (GCIC). Event calendar designed for the worldwide community of the Contact Improvisation Dance form.
MIT License
6 stars 4 forks source link

Problems with CORS #245

Open davide-casiraghi opened 4 years ago

davide-casiraghi commented 4 years ago

Describe the bug Wet got a message from Tinu Hettich (Switzerland)

Hello global CI team. I did some first steps to integrate the global CI calendar into our national website in Switzerland. I did run into problems with CORS.

The javascript test code I used was: ... <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() {. if (this.readyState == 4 && this.status == 200) { myObj = JSON.parse(this.responseText); document.getElementById("demo").innerHTML = myObj.name; } }; xmlhttp.open("GET", 'https://ciglobalcalendar.net/api/teachers', true); xmlhttp.send(); </script>

The error I do get is: CORS header 'Access-Control-Allow-Origin' missing

Same with PHP: <?php ini_set("allow_url_fopen", 1); $curl_handle=curl_init(); curl_setopt($curl_handle, CURLOPT_URL,'https://ciglobalcalendar.net/api/teachers'); curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); $query = curl_exec($curl_handle); $data = json_decode($query, true); curl_close($curl_handle); echo print_r( $data);

Suggested solution I think the solution would be to include the CORS header on your side in the server response. This would ease the integration of the global calendar into national CI websites.