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
17 changes: 16 additions & 1 deletion packages/database/src/core/RepoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ import { RepoInfo } from './RepoInfo';
/** @const {string} */
const DATABASE_URL_OPTION = 'databaseURL';

/**
* This variable is also defined in the firebase node.js admin SDK. Before
* modifying this definition, consult the definition in:
*
* https://github.com/firebase/firebase-admin-node
*
* and make sure the two are consistent.
*/
const FIREBASE_DATABASE_EMULATOR_HOST_VAR = 'FIREBASE_DATABASE_EMULATOR_HOST';

let _staticInstance: RepoManager;

/**
Expand Down Expand Up @@ -80,7 +90,12 @@ export class RepoManager {
* @return {!Database}
*/
databaseFromApp(app: FirebaseApp, url?: string): Database {
const dbUrl: string = url || app.options[DATABASE_URL_OPTION];
let dbEmulatorHost = process.env[FIREBASE_DATABASE_EMULATOR_HOST_VAR];
if (dbEmulatorHost) {
dbEmulatorHost = `http://${dbEmulatorHost}`;
}
const dbUrl: string =
url || dbEmulatorHost || app.options[DATABASE_URL_OPTION];
if (dbUrl === undefined) {
fatal(
"Can't determine Firebase Database URL. Be sure to include " +
Expand Down