i want to make cross domine calls how to allow it from grafana
i was able to do HTTP calls form postman and it was successful
but it i try to do same calls i wail get error like this
XMLHttpRequest cannot load http://grafana.staged-by-discourse.com/api/admin/users. Response for preflight has invalid HTTP status code 404
bluebird.js:1542 Unhandled rejection SuperagentPromiseError: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
auth_basic "Restricted";
auth_basic_user_file /path/to/my/htpasswd/file;
if ($http_origin ~* (https?://[^/]*\.somedomain\.com(:[0-9]+)?)) { #Test if request is from allowed domain, you can use multiple if
set $cors "true"; #statements to allow multiple domains, simply setting $cors to true in each one.
}
if ($cors = 'true') {
add_header Access-Control-Allow-Origin $http_origin; #this mirrors back whatever domain the request came from as authorized, as
add_header "Access-Control-Allow-Credentials" "true"; #as long as it matches one of your if statements
add_header "Access-Control-Allow-Methods" "GET, OPTIONS";
add_header "Access-Control-Allow-Headers" "Authorization, origin, accept";
}
This CORS configuration is not part of the grafana code/config.
Nginx is a reverse proxy server and is just a suggestion. You could do the same thing with Apache, IIS (if you are on Windows) and lots of other servers. Nginx is just the most popular option right now.
A proxy server is a goābetween or intermediary server that forwards requests for content from multiple clients to different servers across the Internet. A reverse proxy server is a type of proxy server that typically sits behind the firewall in a private network and directs client requests to the appropriate backend server. A reverse proxy provides an additional level of abstraction and control to ensure the smooth flow of network traffic between clients and servers.
@robby3 Hey Robby,
Iāve been trying workaround with cors configurations in the nginx but is dont working. Can you please, explaine how and why your nginx configuration works?
The reason this works is because it exposes influxdb behind the same auth mechanism as Grafana.
So, when you login to your main domain via organizr, the iframe will embed the main Grafana domain (https://grafana.mydomain.com), then Grafana will query the influxdb data source (https://grafana.mydomain.com/query) using the same cookies.
I have my influxdb data source setup in Grafana like this;