Thijs Koerselman
Thijs Koerselman

Reputation: 23270

Using functions emulator together with live database

In order to easily test https callable functions, I would like to run the functions emulator in a way that it can assess the online database.

The way to start the emulator I think is this:

"GOOGLE_APPLICATION_CREDENTIALS=\"/path/to/credentials.json\" firebase emulators:start --only functions"

Now I still need to point the firebase functions config in my application to the host/port of the emulator.

Is there a way to do that?

For firestore you can do something like this:

  const db = firebaseApp.firestore();

  if (window.location.hostname === "localhost") {
    console.log("localhost detected!");
    db.settings({
      host: "localhost:8080",
      ssl: false
    });
  }

Is there a similar way to configure firebase functions to point to the emulator?

I know you can test functions via the functions-shell but I don't find that very convenient. I'd like to use my app with already available data from firestore.

Upvotes: 0

Views: 635

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317467

That's not a supported use case. You can use either the cloud service or the local emulator, and not both at the same time. You can try to pre-populate the emulator with some data that you could get from the cloud, but that's about it. (The point of the local emulator is to avoid needing cloud services altogether.)

Upvotes: 2

Related Questions