I have a local area test network 192.168.0.0/26.
On this there are three devices.
-
nginx server 192.168.0.40 serving http://192.168.0.40/energy.html
-
linux kde desktop 192.168.0.10 – chrome browser
-
knx IP interface REST api 192.168.0.9
I have the following js code on the nginx server:
fetch("http://192.168.0.9/baos/GetDatapointValue?DatapointStart=161&DatapointCount=89&Format=Default")
.then(response => console.log(response))
.catch(error => console.log(error));
This fails with a CORS error –
*
Access to fetch at ‘http://192.168.0.9/baos/GetDatapointValue?DatapointStart=161&DatapointCount=4&Format=Default’ from origin ‘http://192.168.0.40’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.*
I would expect a json responce with the knx data.
{
"Result": true,
"Service": "GetDatapointValue",
"Data": [
{
"Datapoint": 161,
"Format": "DPT5",
"Length": 1,
"State": 16,
"Value": 4
},
{
"Datapoint": 162,
"Format": "DPT5",
"Length": 1,
"State": 16,
"Value": 4
},
{
"Datapoint": 163,
"Format": "DPT5",
"Length": 1,
"State": 16,
"Value": 4
},
{
"Datapoint": 164,
"Format": "DPT5",
"Length": 1,
"State": 16,
"Value": 4
}
]
}
If I paste the fetch URL into the browser – this works.
But the js script gives the CORS error.
I think that the schema, the address, and the port are the same so cannot see why I get the CORS error.
Many thanks for any help here