CORS / Access-Control-Allow-Origin



  • Ist it possible to enable CORS at the Evok (Tornado) Webserver an set it the header to "Access-Control-Allow-Origin *"?
    Thank's in advanced



  • Ist it possible to enable CORS at the Evok (Tornado) Webserver an set it the header to "Access-Control-Allow-Origin *"?
    Thank's in advanced



  • I have updated the repository with CORS support, please test it and give me some feedback…

    Tomas



  • Hi Thomas and thank you for you're efforts,

    sorry, didn't get it work. I changed enable_cors in the evok.conf to true and set the cors-domains both to * and loclahost:80. I have the apache web-server setup on port :80 and evok on :2020 and on their own it works fine. It ist important for me to run php and mysql.
    I wanna use the unipi comercial (10 - 20 pcs / year), but therefore the AJAX request from localhost must function.

    I hope for further support and final, good running, solution.



  • Same problem here, I changed the config file in evok/etc/evok.conf
    to
    enable_cors = True
    cors_domains = "*"

    Thanks for your help,

    Denis



  • Hello Denis,

    please try it without the quotation marks… It should work: cors_domains = *



  • Thanks for your answer.

    I changed the file to :
    enable_cors = true
    cors_domains = *

    Then I restart ewok (sudo service evok restart)
    Still having :

    The 'Access-Control-Allow-Origin' header contains the invalid value '"*"'. Origin 'http://localhost:8888' is therefore not allowed access.

    I also tried to reboot the PI with no change….



  • Try it with

    enable_cors = True
    cors_domains = *

    The capital T makes a huge difference.



  • enable_cors = True
    cors_domains = *

    nope…
    (



  • Can you share the client part of the api? Or how do you use it?



  • Javascript + jquery like in :

      				  $.getJSON('http://192.168.1.39/rest/all',function(temp) {
      				  	 $('#SasTemp').html(temp[23].value + '°C');
    
    ```});


  • I just tested this from my laptop to the unipi on a clean raspbian and latest evok from github

    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script>
    	$.getJSON('http://unipi/rest/all',function(devices) {console.log(devices)});
    </script>
    </head>
    <body>
    </body>
    </html>
    
    ```The error```
    XMLHttpRequest cannot load http://unipi/rest/all. The 'Access-Control-Allow-Origin' header contains the invalid value '"*"'. Origin 'null' is therefore not allowed access.
    

    Are you sure you edited the /etc/evok.conf file correctly?