在没有数据库模拟器的数据库上运行firebase函数模拟器(改为生产云) [英] Run firebase functions emulator on database without database emulator (towards production cloud instead)

查看:32
本文介绍了在没有数据库模拟器的数据库上运行firebase函数模拟器(改为生产云)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在生产数据库上运行Firebase功能仿真器.我有一个尚未公开发布的项目,因此我可以在不产生任何负面影响的情况下投入生产.

I am having trouble running the firebase functions emulator towards a production database. I have a project which is not publicly released yet so I can run towards production with any negative effects.

我的项目仅使用实时数据库,不使用Firestore(因此SO上的其他问题不相关).文档状态为"Cloud Firestore和实时数据库触发器已经具有足够的凭据,并且不需要其他设置.";因此,据此,我不需要任何其他设置即可指向生产数据库.

My project uses only the realtime database, it does not use Firestore (so other questions on SO are not relevant) The documentation states "Cloud Firestore and Realtime Database triggers already have sufficient credentials, and do not require additional setup." so according to that, I shouldn't need any additional setup in order to point to the production database.

根据Firebase上的所有文档,如果我仅启动功能仿真器而不启动数据库仿真器,则该项目应朝真正的firebase数据库运行.这个警告似乎也是如此:

According to all of the documentation on Firebase, the project should run towards the real firebase database if I only start the functions emulator and do not start the database emulator. This warning seems to say so, too:

功能:以下仿真器未运行,从功能"仿真器调用这些服务将影响生产:auth,firestore,数据库,托管,pubsub

functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, hosting, pubsub

但是,这不会发生.相反,我收到以下错误:

However, this is not what happens. Instead, I get the following error:

functions [onGlobalClientRequest]:由于数据库模拟器不存在或未在运行,因此忽略了函数.

functions[onGlobalClientRequest]: function ignored because the database emulator does not exist or is not running.

我已经阅读了Firebase文档,除了设置凭据外,什么都没有提到(但我还是要使用 export GOOGLE_APPLICATION_CREDENTIALS ="/path/to/credentials.json" 在运行功能模拟器之前.)

I have read the firebase documentation and nothing is really mentioned other than setting credentials should not be needed (but I am setting credentials anyway using export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json" before running the functions emulator.)

onGlobalClientRequest看起来像这样:

onGlobalClientRequest looks like this:

export const onGlobalClientRequest = functions.database
  .ref( client_requests_key + "/{pushedid}")
  .onCreate(
    async (
      snap: functions.database.DataSnapshot,
      context: functions.EventContext,
    ) => {
      ///.... code here...
    },
  );

推荐答案

本地模拟的Firebase函数将能够写入Prod数据库,但不能由生产数据库触发.

The locally emulated Firebase Functions will be able to write to the Prod database, but will not be able to get triggered by the production database.

这是来自Google员工的 SO答案,上面指出了上述内容.

Here is a SO answer from a Google employee that states the aforementioned.

此外,引用其他Google雇员的 SO答案:

Also, quoting from this other SO answer from another Google employee:

通常,使用emulators:start的规则是,我们全面模拟正在运行的内容.因此,例如,如果您正在运行函数和数据库"模拟器,则所有从函数的写入(通过admin.database()....都将被重定向到数据库模拟器.但是写入到Firestore(admin.firestore()...)将尝试并投入生产,因为该模拟器未运行.

In general the rule with emulators:start is that we comprehensively emulate whatever is running. So for example if you're running the Functions and Database emulator, all writes from functions (through admin.database().... will be redirected to the Database emulator. But writes to Firestore (admin.firestore()...) will try and hit production because that emulator is not running.

这篇关于在没有数据库模拟器的数据库上运行firebase函数模拟器(改为生产云)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆