REST API Call Using Simple-json-datasource

Hi,

I am generating the grafana dashboard by call the REST API (spring-REST) using the simple-json-datasource.
I implemented all the required APIs (/, /search, /query) and maintained the contract as expected.

Also, added the CORS as part of response header and even enabled the CORS for the request API by adding the @CrossOrigin at the @RestController.

When i test the APIs, i m getting following header information in the response of the call
{
“access-control-allow-headers”: “Content-Type, Accept”,
“access-control-allow-methods”: “POST, GET”,
“access-control-allow-origin”: “*”,
“connection”: “keep-alive”,
“content-type”: “application/json”,
“date”: “Thu, 14 May 2020 16:51:18 GMT”,
“keep-alive”: “timeout=60”,
“transfer-encoding”: “chunked”,
“vary”: “Origin, Access-Control-Request-Method, Access-Control-Request-Headers”
}

But while creating the datasource, i was getting the below error
Access to XMLHttpRequest at ‘http://localhost:8888/streams/api/’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed.

Input request for the API call is : curl -X GET --header ‘Accept: application/json’ ‘http://localhost:8888/streams/api/

Any clue?

Any inputs here really appreciated, Thanks

Here are the configurations to enable spring-boot REST service to work with Grafana using simple-json-datasource

  1. API / is of type GET, while /search , /query and /annotations are of method types POST

  2. / API is used for creating the datasource in Grafana

  3. /search API has no input, but the response of this API will be used as a one of the input to /query

  4. /query API, as different response structures depending upon the type of matric selected in dashboard

  5. APIs has to be enabled CORS with origins and allowedHeaders

  6. The response of the API has to have header details

  7. Headers should have access-control-allow-methods , access-control-allow-headers and set to POST and accept, content-type respectively. These two properties are mandatory for the response header