Connect To Firebase Functions Emulators Over Local Network From A Flutter App
I am trying to connect to my Firebase functions emulators from my test Android device. When I run the emulators the output is: ┌────────────────�
Solution 1:
By default, all the emulators will listen to localhost only and not your local network.
I tried replicating your issue by running my hosting emulator on the whole network and functions emulator only on localhost as in the following screenshot.
const firebaseConfig = {...}
firebase.initializeApp(firebaseConfig);
firebase.functions().useEmulator("192.168.0.102", 5001);
var addMessage = firebase.functions().httpsCallable('addMessage');
addMessage({ text: "messageText" }).then((result) => {
// Read result of the Cloud Function.var sanitizedMessage = result.data.text;
});
I copied the sample function from the documentation and tried calling the function and as expected:
If you serve the functions using firebase serve --only functions --host 0.0.0.0
it should make functions available for your network.
Alternatively, you can specify that in your firebase.json
like this:
{
"functions": {
"predeploy": "npm --prefix \"$RESOURCE_DIR\" run build"
},
"emulators": {
"functions": {
"port": 5001,
"host": "0.0.0.0"
}
}
}
Then you can simply start the emulators using firebase emulators:start
.
Post a Comment for "Connect To Firebase Functions Emulators Over Local Network From A Flutter App"