首页 > 解决方案 > firebase 服务后如何访问功能

问题描述

我正在使用 firebase 在我的机器上进行测试。在firebase serve 我只能使用 HTTP 访问功能之后:http://localhost:5001/project/us-central1/endpoint

但是,当我尝试获取参数时。

export const basicHTTP = functions.https.onRequest((req, res) => {
  const name = req.params.name
  res.send(`Hi, good! ${name}`)
})

我无法检索任何参数。我想我必须以 https 访问我的本地主机。

但是我的本地环境不提供通过 SSL 访问的方式。我该如何处理?

标签: node.jsfirebasesslgoogle-cloud-functionsfirebase-tools

解决方案


模拟器使 HTTPS 云功能在本地主机上的 HTTPS和HTTP 上都可用。因此,您可以从代码中通过 HTTP 调用它。

从有关在模拟器中连接到 HTTPS 功能的文档中:

代码中的每个 HTTPS 函数都将使用以下 URL 格式从本地模拟器提供:

http://$HOST:$PORT/$PROJECT/$REGION/$NAME

例如,具有默认主机端口和区域的简单 helloWorld 函数将在以下位置提供服务:

https://localhost:5001/$PROJECT/us-central1/helloWorld

推荐阅读