首页 > 解决方案 > firebase 函数发布数据为空

问题描述

我正在尝试使用 firebase 功能发帖,我正在使用 Blaze 付款计划。无论如何,它无法将发布的数据获取到 TOP 级别的 send_email 函数。我什至还没有接到请求电话。req.body 返回 null,我不知道为什么。

exports.send_email = functions.https.onRequest((req, res) => {
    console.debug(req.body); // THIS IS NULL
    const url = 'https://www.google.com/recaptcha/api/siteverify?secret=<Omitted for security>&response=' + req.body.recaptchaReactive + '&remoteip=' + req.connection.remoteAddress;
    request(url, (body) => {
        //the body is the data that contains success message
        body = JSON.parse(body); // We ALWAYS fail here.
        console.log(body);
        //check if the validation failed
        if (!body) {
            res.end({ success: false, 'message': "recaptcha failed" });
            return console.log("failed")
        }
        if (body.success !== undefined && !data.success) {
            res.end({ success: false, 'message': "recaptcha failed" });
            return console.log("failed")
        }
        //if passed response success message to client
        res.end({ "success": true, 'message': "recaptcha passed" });
    });
});

我正在使用我的角度代码调用该函数,如下所示:

public formSubmit() {
    if (this.contactForm.valid) {
      console.log(this.contactForm.value);
      this.httpClient.post<any>("/send_email", this.contactForm.value).subscribe(d => {
        debugger;
        console.log('sent...', d);
      });
      this.formSentSuccess = true;
    } else {

    }
  }

该函数确实被调用,但似乎没有发送数据。我现在要做的就是取回recaptcha 数据。然后我会发送电子邮件

标签: javascriptfirebasegoogle-cloud-functions

解决方案


推荐阅读