Page 1 of 1

AlarmDecoder-WebApp & CORS

PostPosted: Mon Apr 25, 2016 8:31 am
by brettahale
I have an AD2Pi and just setup the web app using the complete rasbian image. Everything seems to work ok until i try to go to this page:
https://192.168.3.23/static/swagger/index.html

I get this message and the request for the alarmdecoder.json fails due to CORS, Access-Control-Allow-Origin not being set:
Can't read from server. It may not have the appropriate access-control-origin settings.

This API Documentation assumes you are on your local network. To control and test the API through swagger, you must be on your local network. The default address assumes you can resolve the domain alarmdecoder.local - if you cannot, please input the IP address of your AD2PI Network Appliance. (ex: http://192.168.1.100:5000/static/alarmdecoder.json) - or download bonjour for windows Here to resolve the broadcasted alarmdecoder.local domain.


I figured it would be an easy change in nginx and added the CORS headers in the @alarmdecoder location with no luck. Any help would be appreciated.

Code: Select all
    location @alarmdecoder {
        proxy_pass http://127.0.0.1:5000;
        include uwsgi_params;
        uwsgi_param UWSGI_SCHEME $scheme;
        uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;

        if ($request_method = OPTIONS) {
          add_header Access-Control-Allow-Origin "*";
          add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, OPTIONS";
          add_header Access-Control-Allow-Headers "*";
          add_header Access-Control-Allow-Credentials true;
          add_header Content-Length 0;
          add_header Content-Type text/plain;
          add_header Access-Control-Max-Age 1728000;
          return 200;
        }

        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Credentials false;
        add_header Access-Control-Allow-Headers "Content-Type, Accept, Authorization, Origin, User-Agent";
        add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, OPTIONS";

        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header Access-Control-Allow-Origin '*';
        proxy_redirect http://localhost:5000 http://$host;
    }

Re: AlarmDecoder-WebApp & CORS

PostPosted: Mon Apr 25, 2016 10:37 am
by kevin
Hi,

Until we get this figured out in the webapp, you can view the API at http://www.alarmdecoder.com/swagger/

Re: AlarmDecoder-WebApp & CORS

PostPosted: Tue Apr 26, 2016 9:11 am
by brettahale
Cool, thanks for heads up!

Re: AlarmDecoder-WebApp & CORS

PostPosted: Wed Apr 11, 2018 5:47 pm
by yhax
brettahale wrote:Cool, thanks for heads up!


Did you ever manage to get this working locally?

Re: AlarmDecoder-WebApp & CORS

PostPosted: Thu Apr 12, 2018 8:13 pm
by kevin
Kind of fell off the radar as low priority

Re: AlarmDecoder-WebApp & CORS

PostPosted: Thu Jul 08, 2021 12:16 pm
by miragejb
I'm having the same problems. When I click on the "REST API" link on the Advanced Topics -> Developer Resources page, I get the same message above. The link I am using is: https://www.alarmdecoder.com/swagger/

Is there another way I can read the REST API documentation since I can't access it through the website?

Thanks.

Re: AlarmDecoder-WebApp & CORS

PostPosted: Sun Jul 25, 2021 5:49 pm
by kevin
miragejb wrote:I'm having the same problems. When I click on the "REST API" link on the Advanced Topics -> Developer Resources page, I get the same message above. The link I am using is: https://www.alarmdecoder.com/swagger/

Is there another way I can read the REST API documentation since I can't access it through the website?

Thanks.


In the explore box at the top, change the URL to https, ex:make_clickable_callback(MAGIC_URL_FULL, ' ', 'https://www.alarmdecoder.com/alarmdecoder.json', '', ' class="postlink"')