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 ?