Firebase云端函数中的参数HTTPS [英] Parameters in Firebase Cloud Functions HTTPS

查看:120
本文介绍了Firebase云端函数中的参数HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Firebase中的HTTPS功能上设置一些参数?
我正在构建一个应用程序,在构建应用程序的同时,我设法增加了我的邮件列表。现在我想发邮件,但是我想确保在我发送任何东西之前他们可以退订。



我使用的是Firebase的一切功能,并且设法将邮件发送到每个订阅的邮件。



我也可以取消订阅一个特定的邮件,但这是硬编码的,根本不是一个最佳的解决方案。

  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已退订邮件列表);
});

在我发送的邮件中有一个URL,它会触发这个HTTPS函数。我想在该URL上设置一个参数,使其变成动态的。例如:

  https:// us-central1-< project-id> .cloudfunctions.net / testUnsub?listID = xxxxxxxxxxx 

我正在寻找任何可以让我朝正确方向发展的东西。 $ b

解决方案

重要的是要知道你的https函数的req和res参数是 Express.js 请求和响应对象。



请求对象包含来自客户端的所有关于请求的数据,包括 query 。它的形式是 req.query.name_of_the_parameter


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.

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.");
});

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.

解决方案

It's important to know that the req and res parameters to your https function are Express.js Request and Response objects.

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云端函数中的参数HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆