Reactjs 取来http://localhost:3001/ 从铬延伸到反应
我看到过一些类似的问题和解决方案,人们希望在这些问题和解决方案中找到Reactjs 取来http://localhost:3001/ 从铬延伸到反应,reactjs,mongodb,cors,azure-cosmosdb,Reactjs,Mongodb,Cors,Azure Cosmosdb,我看到过一些类似的问题和解决方案,人们希望在这些问题和解决方案中找到http://localhost:3001/some_url并使用cors执行此操作 但我的问题有点不同。我的web应用程序不是一个网站,而是一个web扩展 到目前为止,我还找不到一个办法来接你http://localhost:3001/url 即使使用cors 我尝试的是: 服务器: const cors = require("cors"); app.use(function(req, res, next)
http://localhost:3001/some_url
并使用cors
执行此操作
但我的问题有点不同。我的web应用程序不是一个网站,而是一个web扩展
到目前为止,我还找不到一个办法来接你http://localhost:3001/url 即使使用cors
我尝试的是:
服务器:
const cors = require("cors");
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use(
cors({
origin: "http://localhost:3001/url" // restrict calls to those this address
})
);
在background.js
文件中:
create(urls){
console.log(urls);
return new Promise((resolve, reject) =>{
fetch('https://cors-anywhere.herokuapp.com/'+'http://localhost:3001/url', {
method: 'POST',
body: JSON.stringify(urls),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
"Access-Control-Allow-Origin: *"
}
})
.then(result => result.json())
.then(json => resolve(json))
.catch(err => {
console.log(err);
reject(err);
});
});
}
我还添加了“代理”:http://localhost:3001/url“packages.json中的
我仍然得到错误:
Access to fetch at 'http://localhost:3001/url' from origin 'chrome-extension://extension_id' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://localhost:3001/url' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
有什么办法可以解决这个问题吗?看起来您正在向源代码添加路径/url
,但是:
Web内容的来源由方案(协议)主机定义
(域),以及用于访问它的URL的端口
尝试使用http://localhost:3001
作为原点值。确定。我刚试过。如果我不添加cors anywhere heroku
。。。除了/url
之外,我只收到了相同的错误。如果我添加cors anywhere heroku
。。。。连同http://localhost:3001
我得到了cors-anywhere.herokuapp.com/http://localhost:3001:1 加载资源失败:服务器响应