Skip to content

Commit 568f923

Browse files
authored
infer namespace from subdomain in database emulator environment variable (#2016)
* set database emulator namespace to databaseURL subdomain * [AUTOMATED]: Prettier Code Styling * use let binding for `dbUrl` * [AUTOMATED]: Prettier Code Styling * fix typos * remove unnecessary parser diff * nit * use RepoInfo namespace member for ns query parameter * type spec for `dbUrl` variable
1 parent 4d23d58 commit 568f923

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/database/src/core/RepoManager.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { FirebaseApp } from '@firebase/app-types';
1919
import { safeGet } from '@firebase/util';
2020
import { Repo } from './Repo';
2121
import { fatal } from './util/util';
22-
import { parseRepoInfo } from './util/libs/parser';
22+
import { parseRepoInfo, parseURL } from './util/libs/parser';
2323
import { validateUrl } from './util/validation';
2424
import './Repo_transaction';
2525
import { Database } from '../api/Database';
@@ -90,12 +90,7 @@ export class RepoManager {
9090
* @return {!Database}
9191
*/
9292
databaseFromApp(app: FirebaseApp, url?: string): Database {
93-
let dbEmulatorHost = process.env[FIREBASE_DATABASE_EMULATOR_HOST_VAR];
94-
if (dbEmulatorHost) {
95-
dbEmulatorHost = `http://${dbEmulatorHost}`;
96-
}
97-
const dbUrl: string =
98-
url || dbEmulatorHost || app.options[DATABASE_URL_OPTION];
93+
let dbUrl: string | undefined = url || app.options[DATABASE_URL_OPTION];
9994
if (dbUrl === undefined) {
10095
fatal(
10196
"Can't determine Firebase Database URL. Be sure to include " +
@@ -107,6 +102,11 @@ export class RepoManager {
107102
const parsedUrl = parseRepoInfo(dbUrl);
108103
const repoInfo = parsedUrl.repoInfo;
109104

105+
let dbEmulatorHost = process.env[FIREBASE_DATABASE_EMULATOR_HOST_VAR];
106+
if (dbEmulatorHost) {
107+
dbUrl = `http://${dbEmulatorHost}?ns=${repoInfo.namespace}`;
108+
}
109+
110110
validateUrl('Invalid Firebase Database URL', 1, parsedUrl);
111111
if (!parsedUrl.path.isEmpty()) {
112112
fatal(

0 commit comments

Comments
 (0)