从Angular调用云功能......

时间:2018-06-07 09:10:46

标签: node.js angular firebase stripe-payments google-cloud-functions

我有一个云功能,我需要从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);
}

1 个答案:

答案 0 :(得分:0)

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'作为条件。