use*_*776 1 javascript node.js firebase google-cloud-platform google-cloud-functions
我正在从 Web 应用程序调用一个简单的 firebase 函数,但出现内部错误。有人可以建议我哪里可能出错吗?
我见过类似的问题,但它们没有回答我面临的问题。
我可以确认该功能已部署到 firebase 中。
通过将以下链接粘贴到浏览器中,我得到了响应。 https://us-central1-cureme-dac13.cloudfunctions.net/helloWorld
index.js文件包含代码(Firebase 云函数在index.js 中定义)
const functions = require('firebase-functions');
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
Run Code Online (Sandbox Code Playgroud)
webApp.js具有以下代码(客户端/网站)
var messageA = firebase.functions().httpsCallable('helloWorld');
messageA().then(function(result) {
console.log("resultFromFirebaseFunctionCall: "+result)
}).catch(function(error) {
// Getting the Error details.
var code = error.code;
var message = error.message;
var details = error.details;
// ...
console.log("error.message: "+error.message+" error.code: "+error.code+" error.details: "+error.details)
// Prints: error.message: INTERNAL error.code: internal error.details: undefined
});
Run Code Online (Sandbox Code Playgroud)
您混淆了Callable Cloud Functions和HTTPS Cloud Functions。
通过做
exports.helloWorld = functions.https.onRequest(...)
Run Code Online (Sandbox Code Playgroud)
您定义一个 HTTPS 云函数,
但通过做
var messageA = firebase.functions().httpsCallable('helloWorld');
messageA().then(function(result) {...});
Run Code Online (Sandbox Code Playgroud)
在您的客户端/前端中,您实际上调用了可调用云函数。
您应该将云函数更改为可调用函数,或者helloWorld通过向云函数 URL 发送 HTTP GET 请求来调用/调用 HTTPS 云函数(类似于您在浏览器中“将链接粘贴 https://us-central1-cureme-dac13.cloudfunctions.net/helloWorld到浏览器中”的方式) )。
例如,通过使用Axios库,您可以执行以下操作:
axios.get('https://us-central1-cureme-dac13.cloudfunctions.net/helloWorld')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2120 次 |
| 最近记录: |