我正在尝试在我的 React 应用程序中实现共享点文件浏览器.将 microsoft/file-browser 用于此 ans 代码,如下所示.但是从源 'localhost:3000' 获取 xxx... 已被 CORS 策略阻止
I am trying to implement share point file browser in my react application. Using microsoft/file-browser for this ans code as follows. But getting the xxx... from origin 'localhost:3000' has been blocked by CORS policy
任何想法如何为此启用 CORS
Any ideas how can I enable CORS for this
import * as React from "react"; import { GraphFileBrowser } from '@microsoft/file-browser'; class App extends React.Component { getAuthenticationToken() { return new Promise<string>(resolve => { resolve( "VALID TOKEN" ); }); } render() { return ( <GraphFileBrowser getAuthenticationToken={this.getAuthenticationToken} onSuccess={(selectedKeys: any[]) => console.log(selectedKeys)} onCancel={(err: Error) => console.log(err.message)} endpoint='XXX.sharepoint' /> ); } } export default App; 推荐答案据我所知,CORS 错误不是因为 SharePoint 而发生,而是因为您的浏览器.这里的问题是您正在尝试将资源从 xxx.sharepoint 加载到 localhost(默认情况下,CORS 中永远不会添加该资源)
As far as i can tell the CORS error does not occur because of SharePoint, but because of your Browser. The problem here is that you are trying to load resources from xxx.sharepoint to localhost (which per default is never added as accepted in CORS)
因此,一种解决方案是使用对 CORS 不敏感的浏览器.这可能是以下内容:
So one solution would to use a CORS-unsensitive browser. This could be the following:
cd "C:\Program Files (x86)\Google\Chrome\Application" chrome.exe --disable-web-security --user-data-dir="C:\tmp"此代码段使用用户数据目录C:\tmp"在没有网络安全"(包括 CORS)的情况下启动您的 Google Chrome.
This snippet starts your Google Chrome without "Web Security" (includes CORS) using the User Data Directory "C:\tmp".
请记住,此解决方法仅适用于开发.在生产中你不应该使用 localhost...
Remember that this workaround only works for development. In production you should not use localhost...
www.thepolyglotdeveloper/2014/08/bypass-cors-errors-testing-apis-locally/
更多推荐
如何在 Sharepoint Online 中启用 CORS
发布评论