无法使用Firebase函数获取req.path和req.query.abc [英] Cannot get req.path and req.query.abc with firebase functions
问题描述
我正在尝试在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屋!