Cloud Functions 本地 HTTP 触发器

Cloud Functions Local HTTP Trigger

在使用 firebase-tools 功能 firebase serve 时,execute/trigger 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?目标是 debug/test 在 firebase 托管 + 功能解决方案中启动生产之前的功能。

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

感谢您提供的任何帮助。

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

This command outputs a URL where you can view or test your Firebase hosting content and HTTP functions.

因此,当您启动本地模拟器时,它会为函数打印 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