【问题标题】:Cloud Functions Local HTTP TriggerCloud Functions 本地 HTTP 触发器
【发布时间】:2017-11-26 10:22:27
【问题描述】:

使用firebase-tools 功能firebase serve 时执行/触发Firebase 功能locally 的正确方法是什么?

假设你有这个功能:

exports.hello = functions.https.onRequest((req, res) => {
  res.send('Hello World');
});

如果通常人们会通过对https://us-central1-foobar.cloudfunctions.net/hello 之类的东西进行 HTTP POST 调用来触发生产功能hello,例如:

curl -X POST -H "Content-Type:application/json" https://us-central1-foobar.cloudfunctions.net/hello

在本地使用firebase serve 时如何构造HTTP POST url?目标是在 Firebase 托管 + 功能解决方案中启动生产之前调试/测试功能。

一个目标是localhost:5000 而不是https://us-central1-foobar

感谢您提供的任何帮助。

【问题讨论】:

    标签: javascript firebase google-cloud-functions firebase-tools


    【解决方案1】:

    正如https://firebase.google.com/docs/functions/local-emulator 上的文档所说:

    此命令会输出一个 URL,您可以在其中查看或测试您的 Firebase 托管内容和 HTTP 功能。

    因此,当您启动本地模拟器时,它会打印函数的 URL。就我而言:

    $ firebase serve --only functions
    
    === Serving from '/Users/puf/Github/zero-to-app-io-2017'...
    
    i  functions: Preparing to emulate HTTPS functions. Support for other event types coming soon.
    ✔  functions: cleanupMojaic: http://localhost:5002/z2a-emojichat/us-central1/cleanupMojaic
    

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 2019-04-12
      • 2017-12-18
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      相关资源
      最近更新 更多