【问题标题】:Access local services from firebase cloud functions emulator (ECONNREFUSED connecting to localhost)从 Firebase 云功能模拟器访问本地服务(ECONNREFUSED 连接到 localhost)
【发布时间】:2022-01-05 16:05:54
【问题描述】:

很明显,Firebase Cloud Functions 无法访问 localhost 上的 http 服务,一旦部署 (as per this answer)。但是,在本地运行云函数模拟器时,有没有办法测试本地http服务?

我有一个 node.js 应用程序和各种在 docker 容器中运行的 firebase 模拟器(使用 docker-compose),它们都使用不同的端口。我需要我的云功能向节点应用程序发送一个 POST 请求,我想在我的本地机器上测试这一切。

当我尝试使用 axios 向我的节点应用程序(在 http://localhost:2018)发布请求时,云函数(托管在 http://0.0.0.0:3318)收到 ECONNREFUSED 错误。

【问题讨论】:

    标签: node.js firebase docker docker-compose google-cloud-functions


    【解决方案1】:

    使用 docker-compose 网络的魔力,我发现我可以从我的模拟函数连接到我的 node.js 服务(在我的 docker-compose.yml 中命名为 api),只需使用 url http://api:2018

    【讨论】:

      猜你喜欢
      • 2018-11-29
      • 2021-11-19
      • 1970-01-01
      • 2021-05-13
      • 2019-04-17
      • 2016-07-09
      • 2021-12-02
      • 1970-01-01
      相关资源
      最近更新 更多