Firebase服务-仅功能VS本地仿真器以在本地运行云功能吗? [英] Firebase serve --only functions VS local emulator to run cloud functions locally?

查看:113
本文介绍了Firebase服务-仅功能VS本地仿真器以在本地运行云功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在进行以下操作以在开发过程中本地使用和测试我的功能:

Up until now I've been doing the following to use and test my functions locally during development:

我将其保留在一个终端中:

I leave this running in one terminal:

firebase serve --only functions

并且在初始化Firebase应用程序时将其添加到客户端代码中:

And I add this on my client code when I'm initializing my Firebase app:

const config = {
  apiKey: process.env.FIREBASE_APP_API_KEY,
  authDomain: process.env.FIREBASE_APP_AUTH_DOMAIN,
  databaseURL: process.env.FIREBASE_APP_DATABASE_URL,
  projectId: process.env.FIREBASE_APP_PROJECT_ID,
  storageBucket: process.env.FIREBASE_APP_STORAGE_BUCKET,
  messagingSenderId: process.env.FIREBASE_APP_MESSAGING_SENDER_ID
};

firebase.initializeApp(config);

// THIS IS THE DEFAULT HOST AND PORT USED BY 'firebase serve command'
firebase.functions().useFunctionsEmulator('http://localhost:5000');

我只测试了HTTP可调用函数,到目前为止,它一直运行良好.

但是在文档中,我看到了:

https://firebase.google.com/docs/functions/local-emulator

在本地运行功能 Firebase CLI包括一个Cloud Functions仿真器,可以仿真以下功能类型:

Run functions locally The Firebase CLI includes a Cloud Functions emulator which can emulate the following function types:

  • HTTPS函数
  • 可调用函数
  • Cloud Firestore功能
  • HTTPS functions
  • Callable functions
  • Cloud Firestore functions

在部署到生产环境之前,您可以在本地运行功能以对其进行测试.

You can run functions locally to test them before deploying to production.

1.安装Firebase CLI -链接

2.设置管理员凭据(可选)-链接

$ set GOOGLE_APPLICATION_CREDENTIALS=path\to\key.json
$ firebase emulators:start

完成这些步骤后,您的功能测试可以使用Admin SDK访问Firebase和Google API.例如,在测试身份验证触发器时,仿真函数可以调用admin.auth().getUserByEmail(email).

After completing these steps, your functions tests can access Firebase and Google APIs using the Admin SDK. For example, when testing an Authentication trigger, the emulated function could call admin.auth().getUserByEmail(email).

问题

两种在本地运行函数的方法有什么区别?

What is the difference between the two methods of running functions locally?

推荐答案

firebase emulators:start是新Firebase模拟器套件的一部分,该套件旨在允许多个模拟产品一起工作.它与firebase serve --only functions完全不同,后者基于 @ google-cloud/functions-emulator npm程序包,该程序包未处于主动维护状态(单击进入,您将看到已弃用该程序包).建议您开始迁移到新的仿真器套件,而不要使用firebase serve.

firebase emulators:start is part of the new Firebase emulator suite, which is designed to allow several emulated products work together. It's completely different than firebase serve --only functions, which is based on the @google-cloud/functions-emulator npm package, which is not actively maintained (click through and you will see that it's deprecated). It's recommended that you start moving to the new emulator suite and away from firebase serve.

这篇关于Firebase服务-仅功能VS本地仿真器以在本地运行云功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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