首页 > 解决方案 > 从 Angular 调用 Cloud Function ...

问题描述

我有一个需要从 Angular 服务执行的云功能,该服务在单击按钮时运行。我一直在尝试向它发出 HTTP POST 请求并发送我的数据,但无济于事。我已经解决了它给我的所有错误,但现在它什么也没做......

HTTP云函数

exports.recurringPayment = functions.https.onRequest((req, res) => {
    console.log('Cloud Function running');
    res.status(200).send('Done');
}

角服务

recurringPaymentURL = 'https://recurringpaymenturl.com';
data;
newPost: Observable<any>;

constructor(public http: HttpClient){}

processPayment(user, token){

    this.data = {
    id: 123,
    userID: 23,
    title: 'Some title',
    body: 'Some body'
  }

    //Invoke https function with POST
    this.newPost = this.http.post(this.recurringPaymentURL, this.data);
}

标签: node.jsangularfirebasestripe-paymentsgoogle-cloud-functions

解决方案


HTTP 云函数对节点有语法错误。该功能未正确关闭。

'use strict';

const functions = require('firebase-functions');

exports.recurringPayment = functions.https.onRequest((req, res) => {
  console.log('Cloud Function running');
  res.status(200).send('Done');
});

如果您希望函数特定于 POST 请求,请添加req.method === 'PUT'为条件。


推荐阅读