我需要在Firestore Cloud函数中从http网址提取参数,
HTTP URL
https://us-central-xxxxxxxxxxx.cloudfunctions.net/somefunction?name=ABC&age=80
Firestore Cloud功能
export const somefunction = functions.https.onRequest(async (request, response) => {
var name = // need to extract name from request
var age = // similarly need to extract age from request
}
有人可以帮我吗?
答案 0 :(得分:1)
您可以使用request
对象来访问查询参数,类似于在Express Js中进行的操作
export const somefunction = functions.https.onRequest(async (request, response) => {
var name = request.query.name
var age = request.query.age
}
如果请求来自 POST 请求,则可以使用request.body.*
访问值。
答案 1 :(得分:1)
我遇到类似的问题,无法获得Cannot get req.path and req.query.abc with firebase functions要求的req.url
和req.query.abc
如Call Firebase cloud function via GET and return parameters的注释中所述,这仅在开发中发生。
搜索了很长时间后,我遇到了这篇文章https://howtofirebase.com/cloud-functions-migrating-to-node-8-9640731a8acc,其中说firebase-tools
必须是4.0.0版本。我已经将firebase-tools
更新为4.0.0,并且可以正常获取查询参数