Firebase serve --only functions VS local emulator to 运行 cloud functions locally?
Firebase serve --only functions VS local emulator to run cloud functions locally?
到目前为止,我一直在执行以下操作以在开发期间在本地使用和测试我的功能:
我把这个 运行 留在一个终端里:
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
完全不同,firebase serve --only functions
基于 @google-cloud/functions-emulator npm package,后者未得到积极维护(点击进入,您将看到它已被弃用)。建议您开始迁移到新的模拟器套件并远离 firebase serve
.
到目前为止,我一直在执行以下操作以在开发期间在本地使用和测试我的功能:
我把这个 运行 留在一个终端里:
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
完全不同,firebase serve --only functions
基于 @google-cloud/functions-emulator npm package,后者未得到积极维护(点击进入,您将看到它已被弃用)。建议您开始迁移到新的模拟器套件并远离 firebase serve
.