Firestore 本地 http 与真实数据库:Cloud Firestore 模拟器未运行,因此数据库操作将失败并出现“默认凭据”错误

2024-01-12

我想在本地运行 firebase http 云函数来访问真正的远程 firestore 数据库。

为此,我使用以下命令在本地运行我的函数:

FIREBASE_CONFIG="/path-to-credential.json" GOOGLE_APPLICATION_CREDENTIALS="/path-to-credential.json" firebase emulators:start --only functions

正如这里所写的https://firebase.google.com/docs/admin/setup https://firebase.google.com/docs/admin/setup,这应该允许在没有任何参数的情况下初始化 admin sdk。我的职能index.js如下

import * as admin from 'firebase-admin';
import * as fromHttpFunc from './http/func'; 

admin.initializeApp(); 

export const httpFunc = fromHttpFunc.httpFunc;

当我在浏览器中调用该函数时,这就是我在日志中得到的内容

[warn] ⚠  The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
[debug] [2019-07-20T13:16:28.656Z] [runtime-status] Ephemeral server survived. {}
[info] >  (node:41939) UnhandledPromiseRejectionWarning: Error: The incoming JSON object does not contain a client_email field
[info] >      at JWT.fromJSON (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/google-auth-library/build/src/auth/jwtclient.js:165:19)
[info] >      at GoogleAuth.fromJSON (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:294:16)
[info] >      at GoogleAuth.getClient (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:476:52)
[info] >      at GrpcClient._getCredentials (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/google-gax/build/src/grpc.js:107:40)
[info] >      at GrpcClient.createStub (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/google-gax/build/src/grpc.js:223:34)
[info] >      at new FirestoreClient (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:128:39)
[info] >      at ClientPool.Firestore._clientPool.pool_1.ClientPool [as clientFactory] (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/@google-cloud/firestore/build/src/index.js:315:26)
[info] >      at ClientPool.acquire (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/@google-cloud/firestore/build/src/pool.js:61:35)
[info] >      at ClientPool.run (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/@google-cloud/firestore/build/src/pool.js:114:29)
[info] >      at Firestore.readStream (/Users/michele/dev/clubup/backoffice/firebase/functions/node_modules/@google-cloud/firestore/build/src/index.js:995:26)
[info] >  (node:41939) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
[info] >  (node:41939) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[warn] ⚠  Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
[warn] ⚠  Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.

我不明白出了什么问题,我还通过执行以下操作检查了凭证的路径是否正确cat /path-to-credential.json我有一个 jsonclient_email field.


通过确保以下几点,设法让本地云功能与真正的远程数据库一起工作:

  • run firebase login并登录到您要使用的项目

  • 关注此评论https://github.com/firebase/firebase-functions/issues/121#issuecomment-337065268 https://github.com/firebase/firebase-functions/issues/121#issuecomment-337065268确保该文件不存在(我有一个invalid_grant error)

  • run export GOOGLE_APPLICATION_CREDENTIALS="SERVICE_ACCOUNT_PATH.json"在您要使用的终端会话中(替换 SERVICE_ACCOUNT_PATH)

  • 不使用以下方式为您的 http 功能提供服务firebase emulators:start --only functions但使用firebase serve --only functions。目前,这是一种未记录的行为:https://github.com/firebase/firebase-tools/issues/1412#issuecomment-504561828 https://github.com/firebase/firebase-tools/issues/1412#issuecomment-504561828.

  • 按如下方式初始化应用程序(更新 YOUR_APP_ID):

    admin.initializeApp({ credential: admin.credential.applicationDefault() });

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Firestore 本地 http 与真实数据库:Cloud Firestore 模拟器未运行,因此数据库操作将失败并出现“默认凭据”错误 的相关文章

  • 具有匹配模式的 ioredis 密钥

    我想用键匹配模式 LOGIN 搜索 Redis 数据库 我在我的应用程序中使用 ioredis 昨天我搜索了整个网络 我得到了一些执行这项工作的选项 如下所示 KEYS 扫描流 Issue import Redis from ioredis
  • 找到 Webpack 配置文件但未配置条目

    我正在尝试为我的个人项目组织一个 webpack 2 模板webpack dev server并使用 npm 命令运行它 但我收到此错误 Configuration file found but no entry configured 这很
  • 什么是 Node.js 模块?

    关于这个问题 Node js module exports 的用途是什么以及如何使用它 https stackoverflow com questions 5311334 what is the purpose of nodejs modu
  • setInterval 可以随时间漂移吗?

    我有 2 个 Node js 网络服务器 我在网络服务器内缓存数据 我根据系统时间同步缓存加载 清除 我已经完成了所有主机的时间同步 现在我使用以下代码每 15 分钟清除一次缓存 millisTillNexthour Calculate m
  • 如何模拟 typeorm 连接

    在集成测试中 我使用以下代码片段来创建连接 import Connection createConnection from typeorm ts ignore import options from ormconfig js export
  • Node + Express 与静态 HTML。如何将所有请求路由到index.html?

    我正在开发一个单页 Web 应用程序 使用 Node Express 和 Handlebars 进行模板化 目前 index html 的一切都运行良好 它由一个非常标准的 server js 文件提供 var express requir
  • 为什么我从 findAll Sequelize 得到未定义的电子邮件数据结果?

    请帮忙 如何显示来自 Sequelize findAll 查询的电子邮件 因为我从源代码中得到 Undefine 有人可以帮助我吗 这是我的代码 testdata get req res gt User findAll then data
  • Node.js 有水豚吗?

    有谁知道 Node js 是否有类似 capybara 的东西 怎么样Zombie http zombie labnotes org 僵尸 js 使用 Node js 进行极其快速的无头全栈测试 The Bite 如果你要编写一个速度极快的
  • 如何模拟“焦点”和“打字”事件

    尝试模拟 onfocus 和打字事件 但它不起作用 Sub Login MyLogin MyPass Dim IEapp As InternetExplorer Dim IeDoc As Object Dim ieTable As Obje
  • 将 html2pdf 生成的 pdf 发送回服务器

    我必须使用以下命令发送客户端生成的 PDFhtml2pdf到服务器 我已成功将生成的 PDF 转换为 base64 并希望使用axios 这是我的客户端代码 function myFunction var element document
  • 如何使用 Stripe 在一次操作中创建客户和卡片?

    我正在尝试第一次初始化客户 我有一个表格 他们可以在那里注册和填写所有内容 然后他们提交 在客户端上 会发生以下情况 var cardValues AutoForm getFormValues credit card form insert
  • 如何在 Jenkins 服务器上运行 Jest 测试

    我正在尝试运行我的Jest https facebook github io jest 在 Jenkins 部署期间进行测试 如果我 ssh 进入服务器 我可以 sudo 进入 Jenkins 用户并从工作区成功运行测试 但是 当我尝试从
  • Child_process 处理带有回车符 (\r) 的 STDOUT 流

    我正在编写一个简单的应用程序 它允许工作中的内部系统请求从远程服务器到使用 REST 调用发起的另一个远程服务器的复制过程 使用 rsync 我已经对express框架足够熟悉 并且刚刚开始尝试child process库 并偶然发现了一个
  • express 或express-generator:我需要两者吗?

    只是探索 Node js 并遇到了 Express 在 npm 存储库站点上https www npmjs com package express https www npmjs com package express它明确指出安装是 np
  • MappedListIterable 不是子类型

    我是 flutter 和 dart 的新手 并尝试从 firestore 作为流获取数据并将其提供给我的 ListView 但我不断收到此错误 type MappedListIterable
  • 当请求新页面时,如何将 AngularJS 路由与 Express (Node.js) 结合使用?

    我正在使用 Express 它从静态目录加载 AngularJS 一般情况下我会要求http localhost 其中 Express 为我服务index html以及所有正确的 Angular 文件等 在我的 Angular 应用程序中
  • Firestore 中的多租户

    关于基于子集合值查询数据的实际限制 在 Firestore 中管理多租户的建议方法是什么 我希望能够检索和限制对与用户所属实体 公司相关的数据的访问 数据结构示例 companies companyId users companies co
  • 如何使用 Playwright 使用选择器查找框架 (iframe)

    我有一个小问题 无法找到使用 Microsoft Playwright 框架的答案 根据您可以使用以下代码获取 iframe const frame page frame frame login 但是如何使用选择器来查找 iframe 并与
  • 使用 AWS CDK 为 lambda 指定自定义角色

    我意识到它很新 但我没有看到任何语言的任何示例 说明如何为使用 AWS CDK 创建的 lambda 指定角色 我正在尝试这样做 const cdk require aws cdk cdk const lambda require aws
  • 使用 Jade 评估自定义 javascript 方法 (CircularJSON)

    我想通过 Jade 将一个对象解析为客户端 JavaScript 通常这会起作用 script var object JSON parse JSON stringify object but my object is circular ht

随机推荐