gpt4 book ai didi

javascript - Firebase serve --only functions VS local emulator 在本地运行云功能?

转载 作者:搜寻专家 更新时间:2023-10-31 23:02:55 25 4
gpt4 key购买 nike

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

我让它在一个终端中运行:

firebase serve --only functions

我在初始化我的 Firebase 应用程序时将此添加到我的客户端代码中:

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

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

  • HTTPS functions
  • Callable functions
  • Cloud Firestore functions

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

1. Install the Firebase CLI - Link

2. Set up admin credentials (optional) - Link

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

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).

问题

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

最佳答案

firebase emulators:start 是新的 Firebase 模拟器套件的一部分,旨在让多个模拟产品协同工作。它与 firebase serve --only functions 完全不同,后者基于 @google-cloud/functions-emulator npm package ,它没有得到积极维护(点击进入,您会看到它已被弃用)。建议您开始迁移到新的模拟器套件并远离 firebase serve

关于javascript - Firebase serve --only functions VS local emulator 在本地运行云功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56618725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com