Skip to content

Possibility of more robust emulator detection #1429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
posva opened this issue Sep 11, 2023 Discussed in #1425 · 0 comments
Closed

Possibility of more robust emulator detection #1429

posva opened this issue Sep 11, 2023 Discussed in #1425 · 0 comments
Assignees

Comments

@posva
Copy link
Member

posva commented Sep 11, 2023

Discussed in #1425

Originally posted by luc122c September 8, 2023
I was taking a look at the way Vuefire detects and connects to the Firebase emulators:

export function detectEmulators(
Currently, it uses a combination of environment variables and the firebase.json file to see which emulators should be enabled. However, I believe there is a better option. firebase.json and the env variables just tell the emulator suite the desired ports. While most of the services will shutdown if the port is unavailable, not all do:

⚠  logging: Logging Emulator unable to start on port 4500, starting on 4501 instead.

The firebase emulator hub offers a REST API to query the running emulators and get back the actual host and port in use. I think this would be a more robust solution.

We could simply fetch this endpoint, and capture the host and ports from it. A rough example below:

const emulators = await $fetch<FirebaseEmulatorConfig>(`http://${HOST}:4400/emulators`)
 
if (emulators.firestore) {
  const { host, port } = emulators.firestore;
  connectFirestoreEmulator(firestore, host, port);
}

if (emulators.auth) {
  const { host, port } = emulators.auth;
  connectAuthEmulator(auth, `http://${host}:${port}`);
}

I've been using this in my testing to connect to the emulators and it works fine. Just thought I'd post this idea to get your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant