[英]Firestore cloud functions http onRequest 'POST'
i've set my firestore cloud function to receive an object from the request, but i get an empty body, i get he data from a Form, then pass it to a variable which i want to send in post request to my cloud firestore function, but i get an empty body, even that the cloud function runs, and i can see the log between the result. 我已将我的firestore云函数设置为从请求中接收对象,但是我得到了一个空的主体,我从Form中获取了他的数据,然后将其传递给一个变量,该变量要在请求后发送到我的Cloud Firestore函数中,但是我得到了一个空的身体,即使运行了cloud函数,也可以看到结果之间的日志。 My angular side : 我的侧面:
onSubmit(form:NgForm){
let data = Object.assign({},form.value);
// const httpOptions = {
// headers: new HttpHeaders({
// 'Authorization': 'secret-key'
// }),
// body: 'test'
// };
const dataUser = {
displayName:data.displayName,
email: data.email,
password:data.password
}
console.log(data);
this.http.post(this.endpoint,dataUser).subscribe(res => console.log(res));
}
My node side : 我的节点端:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.AddUser = functions.https.onRequest((req, res) =>{
console.log("B123oo");
console.log(req.body);
console.log("Boo");
// admin.auth().createUser({
// email: body.email,
// emailVerified: false,
// password: body.password,
// displayName: body.displayName,
// disabled: false
// }).then(function(userRecord){
// console.log("OK !!! UID: ",userRecord.uid);
// });
});
result log : 结果日志:
info: User function triggered, starting execution
B123oo
info: {}
Boo
To have a value show as req.body you don't actually assign a value to body. 要将值显示为req.body,实际上并没有为body分配值。 Body is just populated with whatever you send as your data with the request. 正文随随请求一起发送的数据一起填充。 That body would end up being your second value, dataUser. 该主体最终将成为您的第二个值dataUser。 I noticed you're not passing in your httpOptions, which would normally be the 3rd argument passed to post(). 我注意到您没有传递您的httpOptions,通常是传递给post()的第三个参数。 That last part might be your problem. 最后一部分可能是您的问题。 this.http.post(this.endpoint,dataUser,httpOptions)
Good resource: https://itnext.io/working-with-firebase-functions-http-request-22fd1ab644d3 好的资源: https : //itnext.io/working-with-firebase-functions-http-request-22fd1ab644d3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.