我正在使用Firebase功能在Firebase托管下开发一个项目。 Index.js:
exports.simpleFunction = functions.https.onCall((data, context) => {
return data;
});
Index.html:
var simpleFunction = firebase.functions().httpsCallable('simpleFunction');
simpleFunction("12").then (function(result) {
console.log(result);
}).catch(function(error) {
console.log("Error code:" + error.code);
});
在控制台中,我只会得到:
“错误代码:内部”
有人可以帮我弄清楚会发生什么吗?
答案 0 :(得分:1)
我在项目中复制了您的方案,您的代码按预期运行,这是我的HTML文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to Firebase Hosting</title>
<script src="/__/firebase/8.0.0/firebase.js"></script>
<script src="/__/firebase/8.0.0/firebase-app.js"></script>
<script src="/__/firebase/8.0.0/firebase-functions.js"></script>
<script src="/__/firebase/init.js"></script>
<style media="screen">
</style>
</head>
<body>
Hello world!!
</body>
<script>html
let simpleFunction = firebase.functions().httpsCallable('simpleFunction');
simpleFunction("12").then(function (result) {
console.log(result);
}).catch(function (error) {
console.log("Error code:" + error.code);
});
</script>
</html>
我正在使用最新的Firebase Web软件包,并且我的功能支持unauthenticated access。
更新,我能够重现此问题
我尝试调用另一个函数(python函数),但由于python不存在firebase-functions软件包,因此这似乎是根本原因,请尝试更新您的firebase-functions软件包或尝试使用我的复制示例。
package.json
{
"name": "sample-http",
"version": "0.0.1",
"dependencies": {
"firebase-admin": "~9.2.0",
"firebase-functions": "^3.11.0"
}
}
功能
const functions = require('firebase-functions');
exports.simpleFunction = functions.https.onCall((data, context) => {
return data;
});