Datasource Save and Test CORS Orgin error

Hello, I’ve got my local install of Grafana setup on a Ubuntu instance on AWS. I’m using NGINX with the follow config file.

server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm;

location / {
proxy_pass http://localhost:3000/;
add_header Access-Control-Allow-Origin “*”;
add_header Access-Control-Allow-Methods “GET, OPTIONS, POST, PUT”;
add_header Access-Control-Allow-Headers “origin, authorization, accept, content-type”;
}
}

When I setup my datasource, I have an option for PROXY or DIRECT.

When using DIRECT, I have this error:

No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘myweburl.com:3000’ is therefore not allowed access. The response had HTTP status code 401.

When I use proxy, I have this error:

GET myweburl:3000/api/datasources/proxy/1/ 401 (Unauthorized)

I’m a little lost at this point. Any ideas or pointers?

the direct access mode error is due to your data source server not allowing CORS.

The Proxy error seems to be auth related (your data source returns access denied)

Should my nginx config not resolve that? or am I missing something else?

You need to show nginx config for your data source, you only the one for Grafana. CORS error was for your datasource not for grafana

The data source is external. I can get a response via postman GET with no issues.

Yes, but Postman won’t encounter CORS issue in the same way.

I understand that, but I’m using the data source plugin “SimpleJSON”. The data is external from my system, therefore I need to send the correct headers to get around CORS. I’ve configured my NGINX with the proper headers (I thought at least), but it’s still not working.

Where should I be looking to fix this configuration?

The nginx around your external datasource?

How would I have NGINX around a service that I don’t own? Maybe I’m misunderstanding you.

Let’s say I’m calling nodequery’s API to see server stats. They own the API and Service, how could I control that? I’m calling the service fine via Postman and other 3rd party tools, but when I try with Grafana I get this CORS error. I fail to see it’s a “service” problem.

Thanks for all your help so far.

Well the CORS error is due the external service (you datasource) not allowing it to be used from another domain (your Grafana setup).

The CORS issue is solved by using proxy access in you datasource config.