简体   繁体   English

Firebase 云函数:ECONNREFUSED

[英]Firebase Cloud functions: ECONNREFUSED

I am trying the Optimizing Networking of firebase cloud functions like here with Typescript我正在尝试使用 Typescript 像这里一样优化 Firebase 云功能的网络

 const http = require('http'); const functions = require('firebase-functions'); const agent = new http.Agent({keepAlive: true}); export const getXXX = functions.https.onRequest((request, response) => { const req = http.request({ host: 'localhost', port: 443, path: '', method: 'GET', agent: agent, }, res => { let rawData = ''; res.setEncoding('utf8'); res.on('data', chunk => { rawData += chunk; }); res.on('end', () => { response.status(200).send(`Data: ${rawData}`); }); }); req.on('error', e => { response.status(500).send(`Error: ${e.message}`); }); req.end(); });

but I keep getting但我不断得到

error: connect ECONNREFUSED 127.0.0.1:443错误:连接 ECONNREFUSED 127.0.0.1:443

I am not very familiar with TypeScript and js so please help me.我对 TypeScript 和 js 不是很熟悉,所以请帮助我。
Another question when is res.on 'Data' gets triggered ?另一个问题 res.on 'Data' 何时被触发?

You can't access anything on "localhost" (127.0.0.1) in Cloud Functions.您无法访问 Cloud Functions 中“localhost”(127.0.0.1) 上的任何内容。 I suspect that you meant to put a different host in there, and ensure that your project is on the Blaze plan to enable outgoing connections to services not fully controlled by Google.我怀疑您打算在那里放置一个不同的主机,并确保您的项目在 Blaze 计划中,以启用与 Google 未完全控制的服务的传出连接。

原来我需要付费计划才能从我的函数内部发出外部 HTTP 请求。

You can run Cloud Functions on localhost.您可以在本地主机上运行 Cloud Functions。 All you need to do is run a local emulator of the Cloud services.您需要做的就是运行云服务的本地模拟器。 Which Google has provided!谷歌提供的! It's a really awesome tool and a great setup!这是一个非常棒的工具和一个很棒的设置!

Follow these steps for the Firebase tool suite: https://firebase.google.com/docs/functions/local-emulator针对 Firebase 工具套件执行以下步骤: https ://firebase.google.com/docs/functions/local-emulator

Follow these steps for the Cloud tool suite: https://cloud.google.com/functions/docs/emulator针对 Cloud 工具套件执行以下步骤: https : //cloud.google.com/functions/docs/emulator

They are pretty much similar.它们非常相似。

You do not need Blaze plan, you can use the "pay as you go" plan, which includes the free tier quota.您不需要 Blaze 计划,您可以使用“现收现付”计划,其中包括免费套餐配额。 "Free usage from Spark plan included*" https://firebase.google.com/pricing “包括 Spark 计划的免费使用*” https://firebase.google.com/pricing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM