简体   繁体   English

Firebase:如何调试onCall函数?

[英]Firebase: how to debug onCall functions?

I am using Google Cloud Functions Emulator for debugging locally my Firebase functions. 我正在使用Google Cloud Functions Emulator在本地调试Firebase函数。 Firebase recommend to use functions.https.onCall functions instead of functions.https.onRequest for avoid using http calls directly. Firebase建议使用functions.https.onCall .https.onCall 函数代替functions.https.onRequest .https.onRequest,以避免直接使用http调用。 Instead Firebase recommend to use Firebase Functions SDK for call such functions from code. 相反,Firebase建议使用Firebase Functions SDK从代码中调用此类函数。 For functions.https.onRequest I used http-trigger flag but how can I debug onCall functions ? 对于functions.https.onRequest onCall我使用了http-trigger标志,但是如何调试onCall函数呢?

I found a way to run 'onCall' cloud functions locally and call them from a local client. 我找到了一种在本地运行“ onCall”云功能并从本地客户端调用它们的方法。 I still haven't figured out how to attach a debugger but at least I can iterate faster and use console.log statements. 我仍然没有弄清楚如何附加调试器,但是至少我可以更快地迭代并使用console.log语句。

Use firebase serve to host the functions. 使用firebase serve托管功能。 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. 即使这些应该用于http请求,我还是发现firebase客户端具有重写onCall函数的主机名的onCall This takes care of authentication and passing in the right data and context objects for you. 这样可以进行身份​​验证并为您传递正确的数据和上下文对象。

From Terminal in the root of your firebase project folder: 从Firebase项目文件夹根目录中的Terminal中:

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 client: iOS客户端:

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

NOTE: you have to disable App Transport Security in iOS for this to work 注意:您必须禁用iOS中的App Transport Security,此功能才能起作用

NOTE: other clients probably have the same API. 注意:其他客户端可能具有相同的API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM