Skip to content
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
10 changes: 8 additions & 2 deletions packages/database/src/core/util/libs/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export const parseRepoInfo = function(
}

// Catch common error of uninitialized namespace value.
if (!namespace || namespace == 'undefined') {
if (
(!namespace || namespace == 'undefined') &&
parsedUrl.domain !== 'localhost'
) {
fatal(
'Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com'
);
Expand Down Expand Up @@ -124,17 +127,20 @@ export const parseURL = function(
host = dataURL.substring(0, slashInd);
pathString = decodePath(dataURL.substring(slashInd));

colonInd = host.indexOf(':');

const parts = host.split('.');
if (parts.length === 3) {
// Normalize namespaces to lowercase to share storage / connection.
domain = parts[1];
subdomain = parts[0].toLowerCase();
} else if (parts.length === 2) {
domain = parts[0];
} else if (parts[0].slice(0, colonInd).toLowerCase() === 'localhost') {
domain = 'localhost';
}

// If we have a port, use scheme for determining if it's secure.
colonInd = host.indexOf(':');
if (colonInd >= 0) {
secure = scheme === 'https' || scheme === 'wss';
port = parseInt(host.substring(colonInd + 1), 10);
Expand Down
3 changes: 2 additions & 1 deletion packages/database/src/core/util/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ export const validateUrl = function(
if (
!(typeof parsedUrl.repoInfo.host === 'string') ||
parsedUrl.repoInfo.host.length === 0 ||
!isValidKey(parsedUrl.repoInfo.namespace) ||
(!isValidKey(parsedUrl.repoInfo.namespace) &&
parsedUrl.repoInfo.host.split(':')[0] !== 'localhost') ||
(pathString.length !== 0 && !isValidRootPathString(pathString))
) {
throw new Error(
Expand Down
6 changes: 6 additions & 0 deletions packages/database/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ describe('Database Tests', function() {
expect(db.ref().toString()).to.equal('https://foo.bar.com/');
});

it('Can get database with localhost URL', function() {
var db = defaultApp.database('http://localhost:80');
expect(db).to.be.ok;
expect(db.ref().toString()).to.equal('http://localhost:80/');
});

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