繁体   English   中英

Cloud Function Shell中使用Express App调用HTTP函数时如何传递参数

[英]How to pass parameters when invoking HTTP function using Express App in Cloud Function Shell

这类似于之前的一个问题

我正在使用 Express 应用程序在 Firebase Node.js 项目中测试 Cloud Functions,但不知道如何将查询参数添加到我的测试中。

示例代码:

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)

我通过这个调用它:

test.get("/logParams")

这确实记录

这个功能正在执行!

即使在阅读了 firebase 文档firebase 文档中链接的请求自述文件之后,我也不知道如何传入“uuid”查询参数。 我已经尝试了我能想到的一切:

test.get("/logParams?uuid=1234")
test.get("/logParams",{uuid:1234})
...

我怎样才能做到这一点?

这可以通过“qs”参数来完成:

    test.get("/logParams", qs: {uuid:"1234"})

或者在路径本身中包含查询字符串

    test.get("/logParams?uuid=1234")

在你的代码的问题是,不是req.params.uuid你应该使用req.query.uuid

查看req.paramsreq.query 的区别

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM