运行 本地 Firebase

run Firebase locally

我是 Firebase 的新手,现在我正在为它的文档苦苦挣扎 2 个小时,我无法弄清楚如何 运行 我的本地项目与 Firebase(Firebase for web)。

我的应用是这样的:

-- node_modules
-- app
  -- index.html
  -- src
    -- css, js, etc.

基本上我想从 app/index.html 运行 我的应用程序。我已经安装了 firebase tools、运行 firebase init(我不熟悉所有的初始化选项)然后是 运行 firebase serve

它抛出错误 "an unexpected error has occurred",可能是由于缺少 public 目录(但我不想在我的应用程序中使用任何 "public" 目录)。

我也已将我的 Firebase 项目中的 firebase 应用程序代码放入我的 index.html,但它记录了错误:Error: Illegal url for new iframeThis domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.

初始化时,它会创建一个文件:

firebase.json

看起来像这样:

{
  "firebase": "yourProjectName",
  "public": "./someFolder",
  "ignore": []
}

正在提供的文件夹是由 public 属性 指定的文件夹。 所以如果你想为你的项目的应用程序文件夹提供服务,你只需要替换字符串:

  "public": "./app",

发生此错误是因为您没有授权操作。

This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console

您必须使用以下命令通过控制台登录:

firebase login

然后,如果没记错的话,会打开浏览器请求授权

仔细检查传递给 initializeApp() 负载的 authDomain 值。我不小心在 .env 文件的末尾有一个尾随逗号。

当您启动 firebase 配置时,如果您将 https:// 添加到 firebase authDomain,您将无法在 localhost 中使用 firebase 身份验证,因为它不包含 https。从 authDomain URL 中删除 https://。会成功的。