Hello,
I am trying to setup the Firebase Emulators and my app is still connecting to Firebase(web). When I do a db.collection("users").add(), I see the entry on https://console.firebase.google.com not on http://localhost:4000/firestore (host port is 8080, viewer port is 4000)
Here is what I have done to far:
Firebase emulators:start returns "All emulators are ready!"
Firebase.json looks fine (ports look ok)
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"database": {
"port": 9000
},
"hosting": {
"port": 5000
},
"pubsub": {
"port": 8085
},
"ui": {
"enabled": true
}
if (location.hostname === "localhost") {
config.databaseURL = "http://localhost:8080?ns=project_name";
}
firebase.initializeApp(config);
firebase use project_name
I think my problem might be in step 3 but I can't find how to fix it. Have you got any idea? What do you do to make it work?
Thank you!
You're most of the way there but I think the method of connecting to the local database emulators has changed since the video was produced.
I successfully connected to my local db emulator using:
if (!firebase.apps.length) {
let config = {
apiKey: "-------------------",
authDomain: "--------------",
databaseURL: "------------------",
projectId: "----------------",
storageBucket: "---------------------",
messagingSenderId: "--------------",
appId: "----------------------",
measurementId: "-----------------"
};
firebase.initializeApp(config);
if (location.hostname === "localhost") {
var db = firebase.firestore();
db.settings({
host: "localhost:8080",
ssl: false
});
}
}
The original config for online connection is left in place, but if the location.hostname === "localhost", then the change is made appropriately.
firebase.initializeApp(config) needs to be above the if statement that detects local running of the app.
Fortunately, the app continues to use the online authentication and the database and function connections are local.
The up to date documentation is here: https://firebase.google.com/docs/emulator-suite/connect_and_prototype