diff --git a/packages/database/lib/index.js b/packages/database/lib/index.js index 1cb869d02d..73a58d0d8d 100644 --- a/packages/database/lib/index.js +++ b/packages/database/lib/index.js @@ -188,12 +188,22 @@ class FirebaseDatabaseModule extends FirebaseModule { throw new Error('firebase.database().useEmulator() takes a non-empty host and port'); } let _host = host; - if (isAndroid && _host) { - if (_host === 'localhost' || _host === '127.0.0.1') { - _host = '10.0.2.2'; + const androidBypassEmulatorUrlRemap = + typeof this.firebaseJson.android_bypass_emulator_url_remap === 'boolean' && + this.firebaseJson.android_bypass_emulator_url_remap; + if (!androidBypassEmulatorUrlRemap && isAndroid && _host) { + if (_host.startsWith('localhost')) { + _host = _host.replace('localhost', '10.0.2.2'); // eslint-disable-next-line no-console console.log( - 'Mapping database host to "10.0.2.2" for android emulators. Use real IP on real devices.', + 'Mapping database host "localhost" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.', + ); + } + if (_host.startsWith('127.0.0.1')) { + _host = _host.replace('127.0.0.1', '10.0.2.2'); + // eslint-disable-next-line no-console + console.log( + 'Mapping database host "127.0.0.1" to "10.0.2.2" for android emulators. Use real IP on real devices. You can bypass this behaviour with "android_bypass_emulator_url_remap" flag.', ); } }