Dan*_*chs 3 javascript firebase typescript google-cloud-functions
在打字稿上实现一个简单的函数来调用 Firebase 可调用函数是行不通的。使用 firebase-tools@4.0.3 -g、firebase-functions@2.0.5、firebase@5.3.1
Firebase 可调用函数:
import * as functions from "firebase-functions";
exports.httpsOnCall = functions.https.onCall((data, context) => {
console.log(data);
return data;
});
Run Code Online (Sandbox Code Playgroud)
它部署正确
在 webapp 中调用函数:
const a = Firebase.functions.httpsCallable("httpsOnCall");
a.call({ a: 1, b: "testing", c: true }).then(result => {
console.log(result);
});
Run Code Online (Sandbox Code Playgroud)
Firebase 对象初始化:
import * as firebase from "firebase";
const config = {
apiKey: "asdasdasd",
authDomain: "APPNAME.firebaseapp.com",
databaseURL: "https://APPNAME.firebaseio.com",
projectId: "APPNAME",
storageBucket: "APPNAME.appspot.com",
messagingSenderId: "123456"
};
firebase.initializeApp(config);
const Firebase = {
functions: firebase.functions()
}
Run Code Online (Sandbox Code Playgroud)
从 Firebase 登录:
null
Run Code Online (Sandbox Code Playgroud)
从 webapp 登录:
{data: null}
Run Code Online (Sandbox Code Playgroud)
即使填充了上下文变量,数据似乎也没有到达 httpsOnCall 函数。
Jen*_*son 11
而不是执行a.call
,只需调用a
带有参数的函数,如下所示:
const a = Firebase.functions.httpsCallable("httpsOnCall");
a({ a: 1, b: "testing", c: true }).then(result => {
console.log(result);
});
Run Code Online (Sandbox Code Playgroud)
有关示例,请参阅指南。
归档时间: |
|
查看次数: |
2831 次 |
最近记录: |