Firebase serve --only functions VS local emulator to run cloud functions locally?

╄→гoц情女王★ 提交于 2020-06-24 11:07:12

问题


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

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');

I have tested only HTTP callable functions and so far this has been working fine.


But in the docs, I see this:

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

QUESTION

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


回答1:


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.



来源:https://stackoverflow.com/questions/56618725/firebase-serve-only-functions-vs-local-emulator-to-run-cloud-functions-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!