[英]Flutter Web/Dart CORS Error with Firebase Hosting
I wrote an application in Flutter Web.我在 Flutter Web 中编写了一个应用程序。 When I run it in the Browser (debug), I get this error:
当我在浏览器(调试)中运行它时,出现此错误:
cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.googleapis.com/identityto...
When I run it in release mode, I just get this:当我在发布模式下运行它时,我得到了这个:
Error while fetching an original source: NetworkError when attempting to fetch resource.
Source URL: org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/js_helper.dart
According to this Documentation or this Question I have to add something using Expressjs like:根据此文档或此问题,我必须使用 Expressjs 添加一些内容,例如:
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors({ origin: true }));
It seems that indeed, CORS is blocking you from using Firebase to store and access data.似乎确实,CORS 阻止您使用 Firebase 来存储和访问数据。 As per the documentation Configuring cross-origin resource sharing (CORS) :
根据文档配置跨域资源共享(CORS) :
Cross Origin Resource Sharing (CORS) is a mechanism for allowing interactions between resources from different origins, something that is normally prohibited in order to prevent malicious behavior.
跨源资源共享 (CORS) 是一种允许来自不同来源的资源之间进行交互的机制,这通常是为了防止恶意行为而被禁止的。
Considering that, you will need to configure yours to work and accept requests made via HTTP.考虑到这一点,您需要配置您的工作并接受通过 HTTP 发出的请求。 I would recommend you to take a look at the above documentation and the following links, so you can get more information about it.
我建议您查看上述文档和以下链接,以便获得更多相关信息。
Once you have them configured, you should not face both errors anymore, since the requests via HTTP will be authorized via CORS and the access to Firebase should be established.配置它们后,您不应再面临这两个错误,因为通过 HTTP 的请求将通过 CORS 进行授权,并且应该建立对 Firebase 的访问。
Let me know if the information helped you!如果这些信息对您有帮助,请告诉我!
So I was at the same point you were and didn't really want to create Cloud Functions to solve this.所以我和你一样,并不真的想创建 Cloud Functions 来解决这个问题。 I found out that there is a possibility to edit the CORS configuration on firebase.
我发现可以在 firebase 上编辑 CORS 配置。 It's ab it complicated:
这很复杂:
You'll need to install gsutil, authorise it and then edit the CORS configuration.您需要安装 gsutil,对其进行授权,然后编辑 CORS 配置。
You can find more here on the official firebase page您可以在官方 firebase 页面上找到更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.