how to test firebase onCall() locally?

Viewed 2625

I'm trying to use firebase as backend of my android application. But at this early stage it's too slow to deploy to google server and test every new functionality and every fix.

I wonder is it possible to run it locally so my android app can call onCall() functions on localhost:port ?

I've found some .useFunctionsEmulator('http://localhost:8080'); but I'm not sure what import do I need and how exactly to start local "server"

3 Answers

When you start your Firebase Emulators with firebase emulators:start check the log messages to see where your Cloud Functions are running, e.g. functions: Emulator started at http://localhost:5001. You can access then call your function by using firebase.functions().useFunctionsEmulator('http://localhost:5001')

If you are testing on a real device you will have to replace localhost with the IP address of your PC, assuming that PC + device are connected to the same network.

If you are testing on Android Studio's device Emulator you will have to replace localhost with 10.0.2.2, since localhost will point the Emulator to its own localhost address and not your PC's.

This did the trick for me.

I just tested it has i had the same problem and had not found how to solve it because i had ran on outdated information i guess.

So, what i do from my REACT app

i added this line after initializing the firebase app with config:

app.functions().useFunctionsEmulator('http://localhost:5000')

and i use the command "firebase serve" to start the local emulating process.

Note that 5000 is the default port you can change that by adding --port xxxx where xxxx is the port number.

For Android the function is clearly in the doc so i guess it should work too: https://developers.google.com/android/reference/com/google/firebase/functions/FirebaseFunctions

then if you would be testing on the device, meaning not your dev machine then it would not be localhost but the adresse of your machine or you could use ngrok to redirect port and use the temporary link they provide you.

You are looking for:

  firebase.initializeApp(config);
  firebase.functions().useFunctionsEmulator('http://localhost:5001')

Changing 'http://localhost:5001' to whatever your emulator is set to run on

Related