Typescript firebase firestore http函数
我正在从angular应用程序调用firebase firestore http函数,但它总是返回错误 服务台Typescript firebase firestore http函数,typescript,google-cloud-firestore,angular6,google-cloud-functions,Typescript,Google Cloud Firestore,Angular6,Google Cloud Functions,我正在从angular应用程序调用firebase firestore http函数,但它总是返回错误 服务台 constructor(private http: HttpClient, private afs: AngularFirestore, private fns: AngularFireFunctions, private afstorage: AngularFireStorage) { } call(url: string) { this.fns.httpsCallable(u
constructor(private http: HttpClient, private afs: AngularFirestore,
private fns: AngularFireFunctions, private afstorage: AngularFireStorage) { }
call(url: string) {
this.fns.httpsCallable(url)({ text: 'some-data' })
.pipe(first())
.subscribe(resp => {
console.log({ resp });
}, err => {
console.log({ error: err });
});
}
索引
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp()
const cors = require('cors')({ origin: true });
export const hello = functions.region('asia-
northeast1').https.onRequest((data, context) => {
cors(data, context, () => { '' })
console.log('execution started');
console.log('data', data);
return;
});
看起来您正试图使用
onRequest
函数触发器,它需要一个带有响应和请求参数的回调。您需要使用response.send()
将某些内容发送回客户端
或者,您正在使用的结构与https.onCall()配合使用。
请求时的文档
:
onCall的文档
:如何使用onCall请求编写函数?请您解释一下。Richard给出的第二个链接显示了创建可调用函数的文档。我使用链接中给出的示例编写函数,它总是给出一个错误:{状态:“INVALID_参数”,消息:“Bad request”},我的代码怎么了?我不熟悉angular实现,但使用firebase客户端SDK,您可以执行如下可调用函数:firebase.functions().httpscalable('functionName')(requestData)。然后(…)
functions.https.onRequest((request, response) => {
response.send('Success!');
});