[英]Firestore Cloud Function - How to read params from url
I need to extract the params from http url in firestore cloud function,我需要从 firestore 云 function 中的 http url 中提取参数,
HTTP URL HTTP URL
https://us-central-xxxxxxxxxxx.cloudfunctions.net/somefunction?name=ABC&age=80
Firestore Cloud function Firestore 云 function
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
}
Can anyone help me out with this?谁能帮我解决这个问题?
You can use the request
object to access the query parameters similar to what you do in Express Js您可以使用
request
object 来访问类似于您在Express Js中所做的查询参数
export const somefunction = functions.https.onRequest(async (request, response) => {
var name = request.query.name
var age = request.query.age
}
If the request was from a POST request then you can use request.body.*
for accessing values.如果请求来自POST请求,那么您可以使用
request.body.*
来访问值。
I have a similar issue where I cannot get req.url
and req.query.abc
as asked in Cannot get req.path and req.query.abc with firebase functions我有一个类似的问题,我无法获得
req.url
和req.query.abc
,如Cannot get req.path and req.query.abc with firebase functions 中所述
As mentioned in the comments of Call Firebase cloud function via GET and return parameters this is happening only on development.正如通过 GET 调用 Firebase 云 function 并返回参数的评论中提到的,这仅发生在开发中。
After searching for a long time I came across this article https://howtofirebase.com/cloud-functions-migrating-to-node-8-9640731a8acc where it said firebase-tools
have to be of 4.0.0 version.搜索了很长时间后,我发现了这篇文章https://howtofirebase.com/cloud-functions-migrating-to-node-8-9640731a8acc ,其中说 firebase
firebase-tools
必须是 4.0.0 版本。 I've updated my firebase-tools
to 4.0.0 and I can get the query parameters normally我已经将我的
firebase-tools
更新到4.0.0,我可以正常获取查询参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.