【问题标题】:How can I get the params from a "get request" in a firebase function?如何从 firebase 函数中的“获取请求”中获取参数?
【发布时间】:2019-10-10 23:56:37
【问题描述】:

我知道 firebase https.onRequest 中的请求参数对应于 Express 响应。

我想使用这种格式运行云功能(本地测试):

http://localhost:5000/test-2c6e8/us-central1/coins?userid=1

所以,现在我只想从云函数中获取 userId 参数。我写的测试函数是:

exports.coins = functions.https.onRequest((request, response) => 
{
    var db = admin.firestore();
    response.json({query: JSON.stringify(request.query),
                   params: JSON.stringify(request.params),
                   body: JSON.stringify(request.body)});
    response.end();
});

这是我得到的输出:

query   "{}"
params  "{\"0\":\"\"}"
body    "{}"

我尝试了多种方法,但没有任何运气。为什么会这样?

【问题讨论】:

标签: node.js firebase google-cloud-functions firebase-cli


【解决方案1】:

简答是req.query.name_of_the_parameter;对于长答案,您可以阅读here

【讨论】:

  • 救命稻草,谢谢!
猜你喜欢
  • 1970-01-01
  • 2013-08-03
  • 1970-01-01
  • 1970-01-01
  • 2022-01-03
  • 2021-02-04
  • 2019-03-02
  • 2012-01-17
  • 1970-01-01
相关资源
最近更新 更多