响应缺少 CORS header

Missing CORS on the response header

基本上我想知道是否由公司(https://documenu.com/)“修复”他们的端点之一,或者它是否与我的代码有关。

我用下面相同的代码尝试了几乎所有其他端点 (https://documenu.com/docs),除了这里讨论的那个之外,它们都工作正常。

我收到的错误信息是:

Ensure CORS response header values are valid

A cross-origin resource sharing (CORS) request was blocked because of invalid or missing response headers of the request or the associated preflight request.

To fix this issue, ensure the response to the CORS request and/or the associated preflight request are not missing headers and use valid header values.

Note that if an opaque response is sufficient, the request's mode can be set to no-cors to fetch the resource with CORS disabled; that way CORS headers are not required but the response content is inaccessible (opaque).

我试过通过 Node 使用,Live-reload 但没有。

我阅读了有关 CORS 的信息,据我了解,是否将 CORS 添加到他们的回复中取决于公司 headers。

大家怎么看?

感谢您的帮助

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));

是的,你是对的,公司是解决问题的人,因为他们反对发送 CORS header。

使用他们网站上的 API 预览,除了你提到的那个之外,你对所有端点的工作都是正确的。

https://documenu.com/docs#preview_api