无法使用Firebase函数获取req.path和req.query.abc [英] Cannot get req.path and req.query.abc with firebase functions

查看:141
本文介绍了无法使用Firebase函数获取req.path和req.query.abc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在firebase functions中获取请求查询参数和url. 这是我正在使用的代码

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"
        }]
    }
}

package.json中使用"firebase-functions": "^2.3.1"

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

使用firebase serve --only functions在Windows命令提示符下启动firebase功能.当它开始从http://localhost:5000提供数据时,我正在尝试请求http://localhost:5000/coins-app/us-central1/getCoins?repeat=4

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

我在命令提示符中没有收到任何错误,但是只能看到上面的functions/index.js代码中的注释行.

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

推荐答案

您应运行firebase serve并请求 functions.https.onRequest()无法直接接受查询字符串参数.

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

这篇关于无法使用Firebase函数获取req.path和req.query.abc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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