Reputation: 454
I am using node 16 with cloud functions. and I am using Twilio and outlook APIs.
I can access this third party apis in my local system using firebase function serve
,
but when I deploy this functions on GCP, all outgoing request like accessing third party APIs not working and gives error related,
Connection timed out and code: 'ECONNABORTED'.
So how can I fix this ?
Upvotes: 0
Views: 189
Reputation: 3774
In order to allow outgoing requests from Google Cloud Functions with Node.js version 16, you need to configure the environment variable 'FUNCTIONTRIGGERTYPE' to 'http'
.
This can be done by adding the following to the cloud function's configuration file:
environment_variables:
FUNCTION_TRIGGER_TYPE: http
Once the environment variable has been set, you can then use the http module to make outgoing requests from inside your cloud function. For example:
const http = require('http');
exports.myFunction = (req, res) => {
const options = {
hostname: 'example.com',
port: 80,
path: '/',
method: 'GET'
};
const req = http.request(options, (res) => {
// handle response
});
req.end();
};
Additionally, check below points also :
Upvotes: 1