JavaScript Fetch and InfluxCloud

Hello,

I have a question. I am trying to fetch some data from InfluxCloud service with fetch function from JavaScript. Somehow I am able to do it on localhost, but not on InfluxCloud Server. The response that I am getting is:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://earthangel-ed2e3506.influxcloud.net:8086/query?pretty=true&db=test&q=SELECT%20*%20FROM%20data2000. (Reason: expected ‘true’ in CORS header ‘Access-Control-Allow-Credentials’).

and my fetch function looks like this:

var query = "SELECT * FROM data2000"
fetch(“https://earthangel11111.influxcloud.net:8086/query?pretty=true&db=test&q=”+query, {
method: ‘GET’,
credentials: ‘include’,

}).then(function(response) {
response.json().then(function(data) {
jsonObject = data.results[0].series;

})

}).catch(function(err) {
console.log(err)
console.log(“JSON Object not able to be fetched from InfluxDB”)
})

Can anyone please help me?

Kind best regards!

Mile

@smithnblack I dont know if influxdb supports CORS configuration right now. One way to get around this would be to use your server to proxy the request to the database.

I’ve always found this article on CORS helpful.

Thanks for your quick replay. Does anyone else have some other info or helpful tips? The problem is that if I use it over proxy, the performance is not going to be that good as direct connection.

@smithnblack I’m pretty sure that’s the story on InfluxCloud and CORS. Are you seeing a significant performance penalty by proxying?

The Chronograf team is testing with InfluxCloud – for basic dashboarding and data exploration. All of our requests to query endpoints use a proxy that’s built into the Chronograf backend. There’s no CORS issues that way since the proxy is mounted on the same origin as the page is hosted from. We are not observing any significant performance penalty.