[英]How to pass parameters when invoking HTTP function using Express App in Cloud Function Shell
This is similar to a previous question of mine这类似于我之前的一个问题
I'm testing Cloud Functions in a Firebase Node.js project using Express apps, and don't know how to add query parameters to my test.我正在使用 Express 应用程序在 Firebase Node.js 项目中测试 Cloud Functions,但不知道如何将查询参数添加到我的测试中。
Sample code:示例代码:
const logUUID = (req, res) => {
console.log("This function is executing!")
res.send(req.params.uuid)
}
test_app.use("/log_uuid", logUUID)
exports.test = functions.https.onRequest(test_app)
I am calling it through this:我通过这个调用它:
test.get("/logParams")
Which does indeed log这确实记录
This function is executing!
这个功能正在执行!
I don't know how to pass in a 'uuid' query parameter, even after reading the firebase docs and the request readme linked in the firebase docs.即使在阅读了 firebase 文档和firebase 文档中链接的请求自述文件之后,我也不知道如何传入“uuid”查询参数。 I've tried everything I could come up with:
我已经尝试了我能想到的一切:
test.get("/logParams?uuid=1234")
test.get("/logParams",{uuid:1234})
...
How can I do this?我怎样才能做到这一点?
This can be done with a 'qs' argument:这可以通过“qs”参数来完成:
test.get("/logParams", qs: {uuid:"1234"})
Or including the query string in the path itself或者在路径本身中包含查询字符串
test.get("/logParams?uuid=1234")
The problem in your code is that instead of req.params.uuid
you should use req.query.uuid
在你的代码的问题是,不是
req.params.uuid
你应该使用req.query.uuid
See the difference between req.params and req.query查看req.params和req.query 的区别
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.