0

我正在构建一个扩展,并且仅在 azure devops 服务器上遇到了 workItemIcons api 端点的问题,它适用于 azure devops 服务。我要达到的终点是http://...../DefaultCollection/_apis/wit/workItemIcons. 在本地运行扩展时出现以下错误,但即使在已发布版本上也会出现相同类型的错误。

Access to fetch at 'http://...../DefaultCollection/_apis/wit/workItemIcons' from origin 'http://localhost:5500' 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.

我认为扩展范围很好

    "vso.graph",
    "vso.identity",
    "vso.project",
    "vso.profile",
    "vso.work_full",
    "vso.analytics",
    "vso.work"
  ],```

We're using the `azure-devops-extension-api` package.
4

1 回答 1

1

您可以尝试以下方法:

  1. Access-Control-Allow-Origin标题添加到您的响应中。

    例如:

    res.setHeader('Access-Control-Allow-Origin', '*');
    
  2. mode通过设置为绕过 CORS 安全机制no-cors

    例如:

    fetch('http://...../DefaultCollection/_apis/wit/workItemIcons', { mode: 'no-cors' });
    

要查看更多详细信息,您可以参考以下文章:

于 2020-12-31T02:23:20.760 回答