Get response firebase functions from app with Emulators

Viewed 20

How can I get the response of a Firebase function from my app with Emulators?

I am trying the following:

component.ts

getInfo() {
    const functions = getFunctions();
    connectFunctionsEmulator(functions, 'localhost', 5001);

    const getInfo = httpsCallable(functions, 'getFileInformation');
    getInfo()
    .then( (result) => {
      console.log(result.data);
    })
  }

component.html

<button (click)="getInfo()">Get file information</button>

Here the function:

export const getFileInformation = functions.https.onRequest( (req, res) => {

  return cors( req, res, () => {

    const urls = [
      `url1`,
      `url2`,
      `url3`
    ];

    const urlsCalls: any[] = [];
    const resultados: any[] = [];

    urls.forEach( url => {
      urlsCalls.push(axios.get(url));
    });

    Promise.allSettled(urlsCalls)
    .then( response => {
      response.map( (element: any) => {
        const item = element.value.data;
        resultados.push(item);
      });
      console.log(resultados);
      res.json(resultados);
    })
    .catch( error => {
      console.log(error);
    });

  } );


});

function url:

http://localhost:5001/[myProject]/us-central1/getFileInformation

When I click the button, the function is executed, here is the evidence in the Function Emulators:

enter image description here

That is, the function is executed and returns results, but I don't know how to capture them from my app.

The error I get is:

ERROR Error: Uncaught (in promise): FirebaseError: Response is missing data field.
FirebaseError: Response is missing data field.
0 Answers
Related