[go: nahoru, domu]

Skip to content
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

Fix incorrect databaseUrl in Functions emulator #2979

Merged
merged 4 commits into from
Dec 28, 2020
Merged

Conversation

samtstern
Copy link
Contributor

Description

Fixes #2965

Due to the new location support in Realtime Database it is no longer safe to assume that https://<PROJECT-ID>.firebaseio.com is the default RTDB instance location. This PR uses the getAdminSdkConfig REST endpoint to fetch the real database URL and pass it down to the Functions emulator.

In order to make this behavior work offline there are two fallbacks:

  • Successful fetches populate a local cache which can be used when offline.
  • If the cache is empty we can try and guess the Admin SDK config using the old (and not so good) method.

This fallback behavior is based on what we do with web config in the Hosting emulator.

Scenarios Tested

See the setup in #2965. I created a brand new project and created the defalt RTDB through firebase init.

First add a message using the Cloud Function:

$ http http://localhost:5001/fir-tools-2965/us-central1/addMessage?text="hello"
HTTP/1.1 200 OK
connection: keep-alive
content-length: 57
content-type: application/json; charset=utf-8
date: Mon, 28 Dec 2020 18:14:23 GMT
etag: W/"39-bGCJNRIDTzsIri/GyVcXPXLVrbs"
x-powered-by: Express

{
    "result": "Message with ID: -MPeYivLKiIxoGNp2Eil added."
}

I can see that the data goes to the right place in the Emulator UI:
Screen Shot 2020-12-28 at 6 15 19 PM

Finally if I load the hosting emulator I can see the correct logs:
Screen Shot 2020-12-28 at 6 16 21 PM

Sample Commands

N/A

@google-cla google-cla bot added the cla: yes Manual indication that this has passed CLA. label Dec 28, 2020
src/emulator/functionsEmulatorRuntime.ts Outdated Show resolved Hide resolved
@samtstern samtstern merged commit fcb42e0 into master Dec 28, 2020
@cjam
Copy link
cjam commented Jan 21, 2021

@samtstern I recently updated the tools locally and found that I cant get my local database rules to apply to the correct instance anymore. I have my database.rules.json which automatically gets applied to projectId but now the actual database instance id is pulled in from the cloud. How do I configure the local database rules / firebase.json so that the rules apply to this database instance?

@samtstern
Copy link
Contributor Author

@cjam can you file a new issue about this and explain in a little more detail? Definitely sounds like a bug.

@cjam
Copy link
cjam commented Jan 21, 2021

@samtstern I can. I'm a bit busy at the moment to create all of the required details for the bug report but I'll try and get to it in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hosting emulator uses a different RTDB instance from Functions and Database emulators.
3 participants