【发布时间】:2019-11-06 18:01:38
【问题描述】:
我正在为 Vue 应用程序使用 Firebase Hosting/Firestore/Functions。托管 + Firestore 工作正常。 现在我想添加更多功能并想添加功能。为了在本地进行测试,我启动了一个 Firestore,并且可以运行所有 3 个模拟器。 现在,当我启动模拟器并转到托管模拟器时,我可以插入一条记录,该记录也显示在生产数据库中,但未触发该功能。它在创建。 我部署了该功能,它工作正常。我可以看到 console.log()。
为什么本地/生产写入不触发云功能?
函数如下:
export const sendWelcomeEmail = functions.firestore.document('/activeJobsTestDB/{jobId}').onCreate((data,context) => {
const inputRecord = data.data();
console.log('here' + inputRecord);
// const mailOptions = {
// from: '"Spammy Corp." <noreply@firebase.com>',
// to: inputRecord.email,
// };
});
i Starting emulators: ["functions","firestore","hosting"]
⚠ Your requested "node" version "8" doesn't match your global version "12"
✔ functions: Emulator started at http://localhost:5001
i firestore: Serving ALL traffic (including WebChannel) on http://localhost:8080
⚠ firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and will go away soon. Please use port above instead.
i firestore: Emulator logging to firestore-debug.log
✔ firestore: Emulator started at http://localhost:8080
i firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i hosting: Serving hosting files from: dist
✔ hosting: Local server: http://localhost:5000
✔ hosting: Emulator started at http://localhost:5000
i functions: Watching "/Volumes/Work/playground/sforce-job/sforce-jobs/functions" for Cloud Functions...
> here
✔ functions[sendWelcomeEmail]: firestore function initialized.
✔ All emulators started, it is now safe to connect.
我转到 localhost:5000 并可以随意使用我的应用程序,但未触发该功能。任何帮助将不胜感激。
【问题讨论】:
-
您是否尝试通过写入生产 Cloud Firestore 来触发本地云功能?这是行不通的。如果您想将本地 Web 应用程序连接到 Firestore 模拟器,请参阅本指南:firebase.google.com/docs/emulator-suite/…
-
谢谢@SamStern。是的,我意识到它不起作用,我必须创建一个本地模拟数据库。我目前正在创建一个代表 DocumentSnapshot 的 json,然后通过函数 shell 推送它以确保它正常工作。还是谢谢。
-
如果您对如何使用模拟器有更多疑问,请在 firebase-tools GitHub 存储库上提出问题!
-
@SamStern:谢谢伙计!不,我没有更多问题。我自己在存根数据。
标签: firebase google-cloud-firestore google-cloud-functions firebase-hosting firebase-tools