6

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah ok then how do I go about accomplishing what I want to?
As stated in my answer, send a response to the client with res.send(). There's lots of sample code. github.com/firebase/functions-samples

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.