After reading a lot, it seems that I (as well as others) can't really figure out what really terminate a function, and when should you use it. Send, response, redirect, end, return, and a mix of them.
According to Google :
Always end an HTTP function with send(), redirect(), or end()
Now in many questions here i read that response will end your HTTP function as well.A promise will keep it awake.
I would be happy to understand which does what given this function :
exports.server = functions.https.onRequest((request, response) => {
- response.status(200);
- response.status(200).end();
- return
- return response.redirect(someURL);
- sendStatus(200);
- response.status(200).send(dictionary)
When would you use each of this and which will terminate the function.
It's just too confusing and there is no organized document other than a few sentences saying you must terminate the function.
EDIT:
Now it's even more confusing as I read here that response does not terminate the function and you can do things after your response, but you can't edit the response itself because it ended.
So does response terminate the function ?? things are really not clear.
Why can I execute code after "res.send"?