Hello.
There is already similar thread, see here. But no conclusion.
I have Shelly EM device, so this example is related to it.
Standard request in browser is working normally: http://ip.address/emeter/0 -> Response is some JSON {"power":0.00,"reactive":0.00,...}.
But when I try to get data from Javscript with this code:
http_request = new XMLHttpRequest();
http_request.open('get', 'http://ip.address/emeter/0', true);
http_request.setRequestHeader('Content-Type', 'application/json');
http_request.send();
I will get error response in current Chrome: Access to XMLHttpRequest at 'http://ip.address/emeter/0' from origin 'http://different.ip.address' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The reason is that Shelly device will respond just with header Content-Type: application/json, but no Access-Control-Allow-Origin: *. In fact, when I am requesting application/json, there is some "preflight request" from browser to device, which also needs response with access control header...
Can this be fixed globally, or at least can be added some option to menu?
Thanks.