I'm trying to display a Grafana dashboard within a plain PHP page. I followed the website instructions to authentiate with oauth. Here is my code:
<?php
$ch = curl_init();
$authorization = "Authorization: Bearer <myToken>";
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'url-to-my-dashboard',
CURLOPT_HTTPHEADER => array('Content-Type: application/json' , $authorization),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPAUTH => "HTTP/1.1"
));
$output = curl_exec($ch);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php echo $output; ?>
</body>
</html>
The page loads, I get the CSS... but I end up with a 404 error. I discover that Grafana's headers do not allow this kind of actions:
Access to Font at 'http://xxxxx' from origin 'http://localhost'
has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost' is therefore not allowed access.
I'm quite sure I need to configure these headers:
Header set Access-Control-Allow-Origin "xxx"
Header set Access-Control-Allow-Methods "GET, OPTIONS"
Header set Access-Control-Allow-Headers "origin, authorization, accept"
The problem is I don't know where I shall do it. I've been looking for an .htaccess file for Grafana (or Graphite, which we use with it). I've also tried modifying the Apache2 conf file (/etc/apache2/apache2/conf); after restart, nothing changes...
I'm quite stuck. Can anyone help me?