Skip to content

database sdk not correctly inferring emulator namespace name #2064

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 3 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/database/src/core/RepoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ export class RepoManager {
);
}

const parsedUrl = parseRepoInfo(dbUrl);
const repoInfo = parsedUrl.repoInfo;
let parsedUrl = parseRepoInfo(dbUrl);
let repoInfo = parsedUrl.repoInfo;

let dbEmulatorHost: string | undefined = undefined;
if (typeof process !== 'undefined') {
dbEmulatorHost = process.env[FIREBASE_DATABASE_EMULATOR_HOST_VAR];
}
if (dbEmulatorHost) {
dbUrl = `http://${dbEmulatorHost}?ns=${repoInfo.namespace}`;
parsedUrl = parseRepoInfo(dbUrl);
repoInfo = parsedUrl.repoInfo;
}

validateUrl('Invalid Firebase Database URL', 1, parsedUrl);
Expand Down
9 changes: 9 additions & 0 deletions packages/database/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ describe('Database Tests', function() {
expect(db.ref().toString()).to.equal('https://bar.firebaseio.com/');
});

it('Interprets FIREBASE_DATABASE_EMULATOR_HOST var correctly', function() {
process.env['FIREBASE_DATABASE_EMULATOR_HOST'] = 'localhost:9000';
var db = defaultApp.database('https://bar.firebaseio.com');
expect(db).to.be.ok;
expect(db.repo_.repoInfo_.namespace).to.equal('bar');
expect(db.repo_.repoInfo_.host).to.equal('localhost:9000');
delete process.env['FIREBASE_DATABASE_EMULATOR_HOST'];
});

it('Different instances for different URLs', function() {
var db1 = defaultApp.database('http://foo1.bar.com');
var db2 = defaultApp.database('http://foo2.bar.com');
Expand Down