Hello,
I have a template node that is trying to retrieve data with a post request (fetch), I have a CORS policy error that I don't manage to fix.
Access to fetch at 'https://example-elasticsearch/index_3/_search' from origin 'https://mysite.com' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
this is my javascript (in the template node code) :
const userAction = async () => {
console.info('in');
const myBody = {"query": {"bool": {"must": [ { "match": { "My": 4000 }}]}}};
const username = 'hidden';
const password = 'hidden';
const response = await fetch('https://example-elasticsearch/index_3/_search', {
method: 'POST',
body: myBody, // string or object
headers: {
'Content-Type': 'application/json',
"Authorization": 'Basic ' + btoa(username + ":" + password)
}
});
const myJson = await response.json(); //extract JSON from the http response
console.info(myJson);
}
I tried to add this line in the header without any success :
'Access-Control-Allow-Origin': '*'
In my opinion it's not a problem on the server where I retrieve the data because when I try to retrieve the data using an http request node it is working.
Does someone have any idea how I can fix that?
Thanks a lot