如何在不访问Deploy命令返回的URL链接的情况下运行数据库触发器



我试着在谷歌云函数上做我的第一个项目。我尝试了谷歌提供的代码:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
// Take the text parameter passed to this HTTP endpoint and insert it into
// Cloud Firestore under the path /messages/:documentId/original
exports.addMessage = functions.https.onRequest(async (req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into Cloud Firestore using the Firebase Admin SDK.
const writeResult = await admin
.firestore()
.collection("messages")
.add({ original: original });
// Send back a message that we've succesfully written the message
res.json({ result: `Message with ID: ${writeResult.id} added.` });
});

一切都如预期的那样顺利。但是,我必须访问命令返回的url:

$ firebase deploy --only functions

它会返回一个url,我必须访问该url才能运行该函数。我的问题是:对于数据库触发器,我必须通过浏览器打开url才能执行函数吗?

对于数据库触发器,我必须通过浏览器打开url吗执行功能?

否,对于作为后台触发器的数据库触发器(Firestore或实时数据库(,您不需要调用URL:云函数是根据用于定义函数的处理程序(例如,Firestore的onCreate()onUpdate()等,或实时数据库的onWrite()onCreate()等(触发的。

实际上,后台触发的云功能没有可用的URL。

最新更新