Firebase:如何使用Cloud Functions shell在本地运行"HTTPS可调用函数"?

Pet*_*ark 12 firebase google-cloud-functions

我在Firebase官方指南中找不到此用例的解决方案.

  • 它们是HTTPS可调用函数
  • 想要使用Cloud Functions shell在本地运行函数进行测试
  • 函数将接收的数据保存到Firestore
  • 还需要'auth'上下文信息

我的代码如下.提前致谢.


功能:

exports.myFunction = functions.https.onCall((data, context) => {
  const id = context.auth.uid;
  const message = data.message;

  admin.firestore()...
  // Do something with Firestore //
});
Run Code Online (Sandbox Code Playgroud)

客户来电:

const message = { message: 'Hello.' };

firebase.functions().httpsCallable('myFunction')(message)
  .then(result => {
    // Do something //
  })
  .catch(error => {
    // Error handler //
  });
Run Code Online (Sandbox Code Playgroud)

Dom*_*ník 0

云函数有相应的模拟器。检查此链接它可以适合您的情况。它不是功能外壳,但出于测试目的,我认为它仍然可以为你工作