问题
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