Skip to content

support FIREBASE_DATABASE_EMULATOR_HOST env var #2005

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 12 commits into from
Jul 22, 2019
Merged
2 changes: 2 additions & 0 deletions packages/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { setSDKVersion } from './src/core/version';

const ServerValue = Database.ServerValue;

export { FIREBASE_DATABASE_EMULATOR_HOST_VAR } from './src/core/RepoManager';

export function registerDatabase(instance: FirebaseNamespace) {
// set SDK_VERSION
setSDKVersion(instance.SDK_VERSION);
Expand Down
8 changes: 7 additions & 1 deletion packages/database/src/core/RepoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import { RepoInfo } from './RepoInfo';
/** @const {string} */
const DATABASE_URL_OPTION = 'databaseURL';

export const FIREBASE_DATABASE_EMULATOR_HOST_VAR =
'FIREBASE_DATABASE_EMULATOR_HOST';

let _staticInstance: RepoManager;

/**
Expand Down Expand Up @@ -80,7 +83,10 @@ export class RepoManager {
* @return {!Database}
*/
databaseFromApp(app: FirebaseApp, url?: string): Database {
const dbUrl: string = url || app.options[DATABASE_URL_OPTION];
const dbUrl: string =
url ||
app.options[DATABASE_URL_OPTION] ||
'http://' + process.env[FIREBASE_DATABASE_EMULATOR_HOST_VAR];
if (dbUrl === undefined) {
fatal(
"Can't determine Firebase Database URL. Be sure to include " +
Expand Down
1 change: 1 addition & 0 deletions packages/database/src/core/util/libs/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { Path } from '../Path';
import { RepoInfo } from '../../RepoInfo';
import { warnIfPageIsSecure, warn, fatal } from '../util';
import { FIREBASE_DATABASE_EMULATOR_HOST_VAR } from '../../RepoManager';

/**
* @param {!string} pathString
Expand Down