documentation
为了从网页调用位于
us-central1
更准确地说,在网页上
var functions = firebase.functions('europe-west1');
但是我得到了以下错误,并且没有从调用中得到结果:
uncaught exception: functions: Firebase: firebase.functions() takes either no argument or a Firebase App instance. (app/invalid-app-argument).
云函数
const functions = require('firebase-functions');
exports.getName = functions
.region('europe-west1')
.https.onCall((data, context) => {
return { name: 'MyName' };
});
网页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-functions.js"></script>
</head>
<body>
<script>
// Initialize Firebase
var config = {
apiKey: "xxxxxxxxxx",
authDomain: "xxxxxxxxxx",
databaseURL: "xxxxxxxxxx",
projectId: "xxxxxxxxxx",
storageBucket: "xxxxxxxxxx",
messagingSenderId: "xxxxxxxxxx",
};
firebase.initializeApp(config);
var functions = firebase.functions('europe-west1');
var getName = functions.httpsCallable('getName');
getName().then(function (result) {
console.log((result.data));
}).catch(function (error) {
// Getting the Error details.
var code = error.code;
var message = error.message;
var details = error.details;
});
</script>
</body>
</html>
美国中部1
区域(呼叫
firebase.functions()
没有争论)它工作正常。
美国中部1
版本)
const functions = require('firebase-functions');
exports.getName = functions
.https.onCall((data, context) => {
return { name: 'MyName' };
});
美国中部1
版本)
<!DOCTYPE html>
<html lang="en">
.....
<body>
<script>
// Initialize Firebase
var config = {
.....
};
firebase.initializeApp(config);
var functions = firebase.functions();
...
</script>
</body>
</html>
firebase-functions
,
firebase-admin
和
firebase-tools
.