Skip to content

RTDB accepts multi region URL #3050

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

Merged
merged 17 commits into from
May 13, 2020
Merged

RTDB accepts multi region URL #3050

merged 17 commits into from
May 13, 2020

Conversation

fredzqm
Copy link
Contributor

@fredzqm fredzqm commented May 11, 2020

Allow SDK to parse url like my-db.euw1.firebasedatabase.app

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 11, 2020

Binary Size Report

Affected SDKs

  • @firebase/database

    Type Base (a57dac5) Head (3bfd815) Diff
    browser 268 kB 268 kB +74 B (+0.0%)
    esm2017 235 kB 235 kB +76 B (+0.0%)
    main 269 kB 269 kB +74 B (+0.0%)
    module 266 kB 266 kB +74 B (+0.0%)
  • @firebase/firestore

    Type Base (a57dac5) Head (3bfd815) Diff
    browser 249 kB 249 kB -152 B (-0.1%)
    esm2017 194 kB 194 kB -148 B (-0.1%)
    main 490 kB 490 kB -452 B (-0.1%)
    module 247 kB 247 kB -152 B (-0.1%)
  • @firebase/firestore/memory

    Type Base (a57dac5) Head (3bfd815) Diff
    browser 190 kB 190 kB -80 B (-0.0%)
    esm2017 148 kB 148 kB -98 B (-0.1%)
    main 367 kB 366 kB -277 B (-0.1%)
    module 188 kB 188 kB -80 B (-0.0%)
  • firebase

    Type Base (a57dac5) Head (3bfd815) Diff
    firebase-database.js 187 kB 187 kB +42 B (+0.0%)
    firebase-firestore.js 288 kB 288 kB -158 B (-0.1%)
    firebase-firestore.memory.js 230 kB 230 kB -83 B (-0.0%)
    firebase.js 821 kB 821 kB -116 B (-0.0%)

Test Logs

@@ -72,7 +72,7 @@ export const parseRepoInfo = function(
const parsedUrl = parseDatabaseURL(dataURL),
namespace = parsedUrl.namespace;

if (parsedUrl.domain === 'firebase') {
if (parsedUrl.domain === 'firebase.com') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a breaking change for users that use firebase.com?ns=foo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. This is only breaking for firebase/ns?foo which shouldn't affect anyone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe in the past. *.firebase.* will hit this.

My guess is that RTDB was served in firebase.com instead of firebaseio.com in the past.

Added a test for this.

@@ -174,17 +174,17 @@ export const parseDatabaseURL = function(
colonInd = dataURL.length;
}

const parts = host.split('.');
if (parts.length === 3) {
const hostWithoutPort = host.slice(0, colonInd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the slice docs:

"A negative index can be used, indicating an offset from the end of the sequence. slice(2,-1) extracts the third element through the second-to-last element in the sequence."

So, in this case, if no port is specified it seems like we would drop the last character, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no port is specified, colonInd = host.length above, so host.slice(0, host.length) ==> host

} else {
const dotInd = host.indexOf('.');
domain = host.substring(dotInd + 1);
subdomain = host.substring(0, dotInd).toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Flip two lines above to parse string consecutively.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -62,6 +62,15 @@ describe('Database Tests', () => {
expect(db.ref().toString()).to.equal('https://foo.bar.com/');
});

it('Can get database with multi-region URL', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add a test with a non-lowercase namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea.

@fredzqm fredzqm assigned schmidt-sebastian and unassigned fredzqm May 12, 2020
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the new tests.

Can you add an entry to the Changelog? https://github.com/firebase/firebase-js-sdk/blob/master/packages/database/CHANGELOG.md

@fredzqm
Copy link
Contributor Author

fredzqm commented May 12, 2020

Done

@fredzqm fredzqm merged commit 7513890 into master May 13, 2020
@firebase firebase locked and limited conversation to collaborators Jun 13, 2020
@fredzqm fredzqm deleted the fz/multi-region-url branch August 25, 2020 19:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants