如何从Firebase函数中的“获取请求”获取参数?

时间:2019-05-24 11:20:38

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

我知道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    "{}"

我尝试了很多事情,没有任何运气。为什么会这样?

2 个答案:

答案 0 :(得分:2)

最简单的答案是rankabundance(dune,dune.env) rank abundance proportion plower pupper accumfreq logabun rankfreq Poatriv 1 63 9.2 6.0 12.4 9.2 1.8 3.3 Lolipere 2 58 8.5 4.9 12.0 17.7 1.8 6.7 Scorautu 3 54 7.9 5.7 10.0 25.5 1.7 10.0 Bracruta 4 49 7.2 4.6 9.7 32.7 1.7 13.3 Agrostol 5 48 7.0 3.3 10.7 39.7 1.7 16.7 Poaprat 6 48 7.0 4.8 9.2 46.7 1.7 20.0 Trifrepe 7 47 6.9 4.5 9.2 53.6 1.7 23.3 Alopgeni 8 36 5.3 1.8 8.7 58.8 1.6 26.7 Elymrepe 9 26 3.8 1.1 6.5 62.6 1.4 30.0 Planlanc 10 26 3.8 1.2 6.4 66.4 1.4 33.3 Eleopalu 11 25 3.6 0.3 7.0 70.1 1.4 36.7 Anthodor 12 21 3.1 0.8 5.4 73.1 1.3 40.0 Sagiproc 13 20 2.9 0.9 5.0 76.1 1.3 43.3 Juncarti 14 18 2.6 0.4 4.9 78.7 1.3 46.7 Rumeacet 15 18 2.6 0.3 4.9 81.3 1.3 50.0 Achimill 16 16 2.3 0.7 4.0 83.6 1.2 53.3 Bromhord 17 15 2.2 0.4 4.0 85.8 1.2 56.7 Ranuflam 18 14 2.0 0.4 3.7 87.9 1.1 60.0 Bellpere 19 13 1.9 0.6 3.2 89.8 1.1 63.3 Juncbufo 20 13 1.9 0.0 3.8 91.7 1.1 66.7 Salirepe 21 11 1.6 -0.3 3.6 93.3 1.0 70.0 Callcusp 22 10 1.5 -0.3 3.2 94.7 1.0 73.3 Hyporadi 23 9 1.3 -0.4 3.1 96.1 1.0 76.7 Trifprat 24 9 1.3 -0.3 2.9 97.4 1.0 80.0 Airaprae 25 5 0.7 -0.4 1.8 98.1 0.7 83.3 Comapalu 26 4 0.6 -0.3 1.5 98.7 0.6 86.7 Vicilath 27 4 0.6 -0.1 1.3 99.3 0.6 90.0 Empenigr 28 2 0.3 -0.3 0.9 99.6 0.3 93.3 Cirsarve 29 2 0.3 -0.3 0.9 99.9 0.3 96.7 Chenalbu 30 1 0.1 -0.2 0.5 100.0 0.0 100.0 ;对于长答案,您可以阅读here

答案 1 :(得分:0)

也许您必须使用CORS来获取参数

const functions = require('firebase-functions');
const cors = require('cors')({origin: true});
exports.coins = functions.https.onRequest((request, response) => {
    cors(request, response, () => {
        let userUid = request.query.userid;
        console.log("userUid => ", userUid);
        response.status(200).send(userUid);
    })
})
相关问题