I am trying to get InfluxDB version with a simple html/javascript form but i am getting into troubles.
My environment: RaspberryPi CM4, RaspberryPi OS 64bit, InfluxDB Docker(influxdb:latest)
1. /api/v2/ping
returns 404
{
"code": "not found",
"message": "path not found"
}
2. I can not access X-Influxdb-Version
header, probably do to Access-Control-Expose-Headers
is missing
HTTP/1.1 404 Not Found
Access-Control-Allow-Origin: null
Content-Type: application/json; charset=utf-8
X-Influxdb-Build: OSS
X-Influxdb-Version: v2.7.4
X-Platform-Error-Code: not found
Date: Mon, 04 Dec 2023 12:37:05 GMT
Content-Length: 54
InfluxDB 1.8.10 /ping request is fine and i can access X-Influxdb-Version
header
HTTP/1.1 204 No Content
Access-Control-Allow-Headers: Accept, Accept-Encoding, Authorization, Content-Length, Content-Type, X-CSRF-Token, X-HTTP-Method-Override
Access-Control-Allow-Methods: DELETE, GET, OPTIONS, POST, PUT
Access-Control-Allow-Origin: null
Access-Control-Expose-Headers: Date, X-InfluxDB-Version, X-InfluxDB-Build
Content-Type: application/json
Request-Id: f9d2d2a6-9359-11ee-80e6-0242ac11000a
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.8.10
X-Request-Id: f9d2d2a6-9359-11ee-80e6-0242ac11000a
Date: Tue, 05 Dec 2023 10:35:14 GMT
Any help on this?
Test it yourself:
<!doctype html>
<html>
<head>
<title>Get InfluxDB 2 version</title>
<meta charset="UTF-8">
</head>
<body>
<form id="form">
<table>
<tr>
<td>Url:</td>
<td><input id="influx_url" type="text" size="50" value="http://yourhost:8086/api/v2/ping"></td>
</tr>
<tr>
<td>Tocken:</td>
<td><input id="influx_tocken" type="text" size="50" value="yourtocken"></td>
</tr>
<tr>
<td> </td>
<td><button>Get Version</button></td>
</tr>
</table>
</form>
<br>
Version: <span id="influx_version"></span>
<br>
Headers: <span id="influx_header"></span>
<script>
function _id(el) {
return document.getElementById(el);
}
function parseHttpHeaders(httpHeaders) {
return httpHeaders.toLowerCase()
.split("\n")
.map(x => x.split(/: */, 2))
.filter(x => x[0])
.reduce((ac, x) => { ac[x[0]] = x[1]; return ac; }, {});
}
function getVersion() {
const request = new XMLHttpRequest();
request.open("POST", _id('influx_url').value);
request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
request.setRequestHeader("Authorization", "Token " + _id('influx_tocken').value);
request.setRequestHeader("Accept", "application/json");
request.onreadystatechange = () => {
var headers = parseHttpHeaders(request.getAllResponseHeaders());
_id('influx_version').innerHTML = headers['x-influxdb-version'];
_id('influx_header').innerHTML = request.getAllResponseHeaders().toLowerCase();
};
request.send();
}
const form = _id("form");
form.addEventListener("submit", function (event) {
event.preventDefault();
getVersion();
});
</script>
</body>
</html>