问题描述
如何在 Firebase 中为我的 HTTPS 函数设置一些参数?我正在构建一个应用程序,在构建应用程序的同时,我设法增加了我的邮件列表.现在我想发送邮件,但我想确保他们可以在我发送任何内容之前取消订阅.
How can I set some parameters on my HTTPS functions in Firebase?I am building an app, and while building the app, I have managed to grow my mailing list. Now I want to send mails out, but I want to make sure that they can unsubscribe before I send anything out.
我使用 Firebase 来处理所有事情,并且我已经设法创建了一个功能,可以将邮件发送到每个订阅的邮件.
I am using Firebase for everything, and I have managed to make a function that sends mails out to every subscribed mail.
我还可以取消订阅"特定邮件,但这是硬编码的,根本不是最佳解决方案.
I am also able to "unsubscribe" a specific mail, but that is hardcoded, and not at all an optimal solution.
exports.testUnsub = functions.https.onRequest((req, res) => {
var db = admin.database();
var ref = db.ref("mailingList/-KhBOisltrOmv57Mrzus");
ref.child("subscribed").set(false);
console.log("-KhBOisltrOmv57Mrzus has unsubscribed from mailing list.");
});
在我发送的邮件中有一个 URL,它触发了这个 HTTPS 功能.我想在该 URL 上设置一个参数,使其变为动态的.比如:
In the mail I send there is an URL, which triggers this HTTPS function. I want to set a parameter on that URL so it becomes dynamic. Something like:
https://us-central1-<project-id>.cloudfunctions.net/testUnsub?listID=xxxxxxxxxxx
我正在寻找任何能让我朝着正确方向前进的东西.
I am looking for anything that can get me on the right direction.
推荐答案
重要的是要知道你的 https 函数的 req 和 res 参数是 Express.js 请求和响应对象.
It's important to know that the req and res parameters to your https function are Express.js Request and Response objects.
Request 对象包含有关来自客户端的请求的所有数据,包括客户端在 URL 中发送的 查询.它将采用 req.query.name_of_the_parameter
的形式.
The Request object contains all the data about the request coming from the client, including the query that the client sent in the URL. It will take the form req.query.name_of_the_parameter
.
这篇关于Firebase Cloud Functions HTTPS 中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!