Is it the company's responsibility () to rectify one of their endpoints or is it an issue with my code?
I have tested all other endpoints () using the same code below and they all function correctly, except for the specific one in question.
The error message I encountered reads as follows:
Ensure CORS response header values are valid
A cross-origin resource sharing (CORS) request was blocked due to missing or invalid response headers in the request or the associated preflight request.
To resolve this problem, make sure that the response to the CORS request and/or the corresponding preflight request contain the necessary headers with valid values.
Keep in mind that if an opaque response suffices, the request mode can be set to no-cors to fetch the resource without CORS, although this would render the response content inaccessible (opaque).
I have attempted various methods like Node and Live-reload, but the issue persists.
I have studied about CORS and as far as I understand, it is the company's responsibility to include CORS in their response headers.
What are your thoughts on this matter?
const api = apiKey;
const myHeaders = new Headers();
myHeaders.append('x-api-key', api);
const requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow',
mode: 'cors',
};
const endpoint = 'https://api.documenu.com/v2/menuitems/search/geo?lat=40.688072&lon=-73.997385&distance=1&search=buffalo%20chicken';
fetch(`${endpoint}`, requestOptions)
.then((res) => res.json())
.then((data) => console.log(data));