node.js - 从 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);
}
解决方案
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'
为条件。
推荐阅读
- excel - 比较两个工作表中 A 行的文本,如果找不到则添加
- javascript - 将 javascript Promise 值作为参数传递给构造函数
- submenu - Android BottomAppBar 动态子菜单配置
- python - 打印用于复制和粘贴的 numpy 数组
- r - 如何正确绘制主轴回归的置信区间(使用 lmodel2)?
- rxjs - RXJS 更新主题类似于 Svelte 商店?
- r - 理解如何加载数据以估计协方差矩阵的问题 - R
- linux - 通过 CWagent / Alert / 如何识别实例的日志监控
- unix - ELF 文件和进程控制块之间的关系
- rust - 使用通知示例设置民意调查观察者