【问题标题】:Invoke Cloud Function ... from Angular?从 Angular 调用 Cloud Function ...
【发布时间】:2018-11-17 03:21:53
【问题描述】:

我有一个需要从 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.js angular firebase stripe-payments google-cloud-functions


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-12-17
      • 2018-08-13
      • 2020-10-31
      • 2018-01-24
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      相关资源
      最近更新 更多