Cannot get req.path and req.query.abc with firebase functions

别说谁变了你拦得住时间么 提交于 2019-12-24 12:34:02

问题


I'm trying to get the request query params and url in firebase functions. Here is the code I'm using

firebase.json

{
    "hosting": {
        "public": "build",
        "rewrites": [{
            "source": "/getCoins",
            "function": "getCoins"
        }]
    }
}

Using "firebase-functions": "^2.3.1" in package.json

functions/index.js

'use strict';
const functions = require('firebase-functions');
exports.getCoins = functions.https.onRequest((req, res) => {
    console.log(req.query); // [object Object]
    console.log(req.query.repeat); // empty
    console.log(req.url); // '/'
    console.log(req.originalUrl); // '/'
    res.sendStatus(200);
});

Started the firebase functions in my windows command prompt using firebase serve --only functions. As it starts serving data from http://localhost:5000, I'm trying to request http://localhost:5000/coins-app/us-central1/getCoins?repeat=4

I'm not getting any error in the command prompt, but could only see the commented lines from the above functions/index.js code.


回答1:


You should run firebase serve and request to http://localhost:5000/getCoins?repeat=4 .

functions.https.onRequest() can't accept query string parameter directly.



来源:https://stackoverflow.com/questions/56305935/cannot-get-req-path-and-req-query-abc-with-firebase-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!