Firebase 云功能:ECONNREFUSED [英] Firebase Cloud functions: ECONNREFUSED

查看:22
本文介绍了Firebase 云功能:ECONNREFUSED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Typescripthere 优化 Firebase 云功能的网络

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();
});

但我不断得到

错误:连接 ECONNREFUSED 127.0.0.1:443

error: connect ECONNREFUSED 127.0.0.1:443

我对 TypeScript 和 js 不是很熟悉,所以请帮助我.
另一个问题 res.on 'Data' 何时被触发?

I am not very familiar with TypeScript and js so please help me.
Another question when is res.on 'Data' gets triggered ?

推荐答案

您无法访问 Cloud Functions 中localhost"(127.0.0.1) 上的任何内容.我怀疑您打算在其中放置一个不同的主机,并确保您的项目在 Blaze 计划中,以启用与不受 Google 完全控制的服务的传出连接.

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 云功能:ECONNREFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆