I\'m exploring the firebase cloud functions and I\'m trying to send a notifications with an http request.
The problem is that even if I manage to send the notificati
HTTP-triggered Cloud Functions work just like Express apps -- you have a response object (res
) that you need to use to send something when the request is done. In this case, it looks like you could do something like:
return Promise.all([
/* ... */
]).then(() => {
res.status(200).send('ok');
}).catch(err => {
console.log(err.stack);
res.status(500).send('error');
});
@Michael Bleigh answer is perfectly fine for this question, let me add more in this for the future users.
As per firebase documentation:-
Use these recommended approaches to manage the lifecycle of your functions:
Resolve functions that perform asynchronous processing (also known as "background functions") by returning a JavaScript promise.
Terminate HTTP functions with
res.redirect()
,res.send()
, orres.end()
. (The case in this question.)Terminate a synchronous function with a
return;
statement.
Note It's important to manage the lifecycle of a function to ensure that it resolves properly. By terminating functions correctly, you can avoid excessive charges from functions that run for too long or loop infinitely. Also, you can make sure that the Cloud Functions instance running your function does not shut down before your function successfully reaches its terminating condition or state.
You might see below warning in firebase functions log if the billing account is not configured.
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
Check this link for more information.