Firebase serve --only functions VS local emulator 在本地运行云功能? [英] Firebase serve --only functions VS local emulator to run cloud functions locally?

查看:26
本文介绍了Firebase serve --only functions VS local emulator 在本地运行云功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 函数

我在初始化 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 函数

您可以在本地运行函数以在部署到生产之前对其进行测试.

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

1.安装 Firebase CLI - 链接

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

$ set GOOGLE_APPLICATION_CREDENTIALS=path	okey.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 serve --only functions VS local emulator 在本地运行云功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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