函数时出现Access"/>
尝试调用Firebase函数时出现Access
请阅读,这是不同的!
我以前使用过Firebase Functions,并通过添加以下代码解决了此问题:
const cors = require('cors')({ origin: true });
return cors(req, res, () => {
let format = req.query.format;
if (!format) {
format = req.body.format;
}
const formattedDate = moment().format(format);
console.log('Sending Formatted date:', formattedDate);
res.status(200).send(formattedDate);
});
但是现在我正在研究一个新项目,无论我做什么,都会遇到此错误。
我已经在stackoverflow和互联网上阅读并尝试了20多个其他问题的解决方案,但现在都无济于事。
所以我去了Firebase的GitHub,下载了date example(已实施建议的cors修复程序并进行了部署。
而且我仍然遇到相同的错误!
Access to fetch at '' from origin
'http://localhost:3000' 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.
- 该函数可以从邮递员处调用并起作用。 .png
- 我已经将项目升级为出色的计划(没有帮助)。
- 我尝试更改为origin:“ http://localhost:3000”]]而不是origin:true,这根本没有帮助。
- 我尝试将我的应用程序上传到服务器并从那里调用,结果相同(http,而不是https)-即使设置origin:“ ”
任何指针将不胜感激。
请阅读,这是不同的!我以前使用过Firebase Functions,并通过添加以下代码解决了此问题:const cors = require('cors')({origin:true});返回cors(req,res,()=> {...
回答如下:问题是从本地主机进行的查询缺少CORS标头。
更多推荐
尝试调用Firebase函数时出现Access
发布评论