Firebase Cloud功能:ECONNREFUSED [英] Firebase Cloud functions: ECONNREFUSED
问题描述
我正在尝试使用Typescript 此处来优化Firebase云功能的网络/p>
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({主机:"localhost",端口:443,小路: '',方法:"GET",代理商:代理商,},res =>{让rawData ='';res.setEncoding('utf8');res.on('数据',块= >> {rawData + =块;});res.on('end',()=> {response.status(200).send(`Data:$ {rawData}`);});});req.on('error',e => {response.status(500).send(`Error:$ {e.message}`);});req.end();});
但我不断得到
错误:连接ECONNREFUSED 127.0.0.1:443
我对TypeScript和js不太熟悉,所以请帮助我.
另一个问题是何时触发数据"解析??
您无法访问Cloud Functions中"localhost"(127.0.0.1)上的任何内容.我怀疑您打算在其中放置其他主机,并确保您的项目在Blaze计划中,以实现与不受Google完全控制的服务的传出连接.
I am trying the Optimizing Networking of firebase cloud functions like here with Typescript
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
I am not very familiar with TypeScript and js so please help me.
Another question when is res.on 'Data' gets triggered ?
You can't access anything on "localhost" (127.0.0.1) in Cloud Functions. 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.
这篇关于Firebase Cloud功能:ECONNREFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!