Firebase:如何调试onCall函数? [英] Firebase: how to debug onCall functions?

查看:64
本文介绍了Firebase:如何调试onCall函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Google Cloud Functions Emulator 在本地调试我的Firebase函数. Firebase建议使用functions.https.onCall 功能代替functions.https.onRequest以避免使用http直接调用.相反,Firebase建议使用 Firebase Functions SDK 从代码中调用此类函数. 对于functions.https.onRequest,我使用了http-trigger标志,但是如何调试onCall函数?

I am using Google Cloud Functions Emulator for debugging locally my Firebase functions. Firebase recommend to use functions.https.onCall functions instead of functions.https.onRequest for avoid using http calls directly. Instead Firebase recommend to use Firebase Functions SDK for call such functions from code. For functions.https.onRequest I used http-trigger flag but how can I debug onCall functions ?

推荐答案

我找到了一种在本地运行"onCall"云函数并从本地客户端调用它们的方法.我仍然没有弄清楚如何附加调试器,但是至少我可以更快地迭代并使用console.log语句.

I found a way to run 'onCall' cloud functions locally and call them from a local client. I still haven't figured out how to attach a debugger but at least I can iterate faster and use console.log statements.

使用firebase serve托管功能.即使这些应该用于http请求,我仍然发现firebase客户端具有覆盖onCall函数的主机名的属性.这样可以进行身份​​验证并为您传递正确的数据和上下文对象.

Use firebase serve to host the functions. Even though these are supposed to be for http requests I found that the the firebase clients have a property to override the host name for onCall functions. This takes care of authentication and passing in the right data and context objects for you.

从Firebase项目文件夹根目录中的终端机中:

firebase serve

您应该在终端窗口中获​​得成功的结果.输入主机名和端口号:

You should get a successful result in the terminal window. Take the hostname and port number:

✔ functions: helloWorld: http://localhost:5000/your-project-name/us-central1/helloWorld

iOS客户端:

Functions.functions().useFunctionsEmulator(origin: "http://localhost:5000")

注意:您必须在iOS中禁用App Transport Security,此功能才能起作用

NOTE: you have to disable App Transport Security in iOS for this to work

注意:其他客户端可能具有相同的API.

NOTE: other clients probably have the same API.

这篇关于Firebase:如何调试onCall函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆