node.js - Firebase 云功能模拟器可以使用生产 Firestore 调用触发器吗?
问题描述
我正在尝试在具有真实生产 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")
}
解决方案
推荐阅读
- docker - 使用 docker 在机器之间持久化 influxDB 数据
- python - 将 Adaboost 与随机森林基础分类器一起使用?
- php - 查询自定义帖子类型,在查询中使用自定义字段/元键
- java - 获取:运行spring项目时reactor.netty.resources.ConnectionProvider$Builder的正确类路径
- ios - 在这种情况下,Xcode 调试内存图和 Instruments 都无法检测到泄漏?
- npm - 在 npm 上出现错误,我该如何解决?
- python - 如何使用索引列表对熊猫列进行切片?
- python - 将单个数据框(左)与列表中的多个数据框(右)组合
- java - SAP CX (HYBRIS) : 如何从保存的购物车中删除已删除的产品
- ios - Flutter url_launcher换行符在iOS邮件程序中不起作用