我正在尝试使用 Typescript 优化 firebase 云功能的网络,例如here
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我对 TypeScript 和 js 不太熟悉,所以请帮助我。
另一个问题 res.on 'Data' 何时被触发?