尝试调用Firebase函数时出现Access

编程入门 行业动态 更新时间:2024-10-08 14:47:47

尝试调用Firebase<a href=https://www.elefans.com/category/jswz/34/1771370.html style=函数时出现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

本文发布于:2024-05-07 15:16:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756875.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   Firebase   Access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!