Skip to content

Commit

Permalink
fix(database): database emulator config respects android_bypass_emula…
Browse files Browse the repository at this point in the history
…tor_url_remap flag

this was an oversight in previous versions, the firebase.json flag to ignore
the built-in android localhost -> 10.0.2.2 remapping for transparently-working
emulator out of the box for the general case was ignored
  • Loading branch information
mikehardy committed Feb 10, 2025
1 parent cb4ac46 commit 7bac573
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/database/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
}
}
Expand Down

0 comments on commit 7bac573

Please sign in to comment.