Firebase云功能模拟器可以使用生产Firestore调用触发器吗?

时间:2020-06-07 07:40:02

标签: node.js firebase google-cloud-firestore google-cloud-functions firebase-cli

我正在尝试在具有实际生产Firestore的模拟器上测试Firebase云功能。启动功能模拟器时,出现错误i functions[sendPushOnNewMessage]:function ignored because the firestore emulator does not exist or is not running.,有趣的是,我可以从firestore中读取(从生产数据中读取),但是firebase仿真器拒绝允许这些功能启动。

❯ firebase emulators:start --only functions
i  emulators: Starting emulators: functions
i  ui: Emulator UI logging to ui-debug.log
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /Users/.../functions/3afae-a81e699d1cf0.json. Non-emulated services will access production using these credentials. Be careful!
⚠  functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
>  Starting up...
i  functions[createUserRecord]: function ignored because the auth emulator does not exist or is not running.
i  functions[sendPushOnNewMessage]: function ignored because the firestore emulator does not exist or is not running.

这是我使用服务帐户进行设置的方式(我知道这是可行的,因为我可以阅读文档):

// Service account initialization.
let serviceAccount = require('./3afae-a81e699d1cf0.json');
var initOptions = {}
emulator#set_up_admin_credentials_optional.
if (process.env.FUNCTIONS_EMULATOR) {
  initOptions.credential = admin.credential.cert(serviceAccount)
}
admin.initializeApp(initOptions);
const firestore = admin.firestore();

我的触发功能示例:

exports.sendPushOnNewMessage = functions.firestore.document('chats/{chatID}/messages/{messageID}').onCreate((change, context) => {
    console.log("Trigger called")
}

0 个答案:

没有答案