Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get return values from firebase functions?

I'm trying to get json from a firebase function request, here's what I'm trying:

export const listener = functions.https.onRequest(async (req, res) => {
    return {foo:"bar"}
}) 

unfortunately this yields a timeout with no result when I go to the appropriate url in chrome, I also tried:

function getDude(){
    return {dude:"dude"};
}

export const listener = functions.https.onRequest(async (req, res) => {
    return Promise.all([getDude()]);
}) 

Same result as before.

like image 650
meds Avatar asked Dec 13 '17 20:12

meds


1 Answers

HTTPS type functions don't return promises, so you should not declare them async. (However, all of the other types of Cloud Functions do require that you return promises for any async work they perform.)

HTTPS type functions are obliged to return a result to the client in order to terminate the function. This is as simple as using res.send(), or any of the methods described in the documentation. That's not to say you shouldn't be using promises in the function to wait for async work to complete - you just don't return one from the function.

like image 181
Doug Stevenson Avatar answered Sep 20 '22 14:09

Doug Stevenson