Skip to content

Commit 777c206

Browse files
committed
Cleanup & functions
1 parent 8294d2d commit 777c206

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

packages/functions/src/api.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
httpsCallable as _httpsCallable,
2828
httpsCallableFromURL as _httpsCallableFromURL
2929
} from './service';
30-
import { getModularInstance } from '@firebase/util';
30+
import { getModularInstance, getDefaultEmulatorHost } from '@firebase/util';
3131

3232
export * from './public-types';
3333

@@ -51,12 +51,10 @@ export function getFunctions(
5151
const functionsInstance = functionsProvider.getImmediate({
5252
identifier: regionOrCustomDomain
5353
});
54-
if (app.name === '[DEFAULT]' || app.name.startsWith('authenticated-context:')) {
55-
const functionsEmulatorHost = (globalThis as any).__FUNCTIONS_EMULATOR_HOST__;
56-
if (functionsEmulatorHost) {
57-
const [ host, port ] = functionsEmulatorHost.split(':');
58-
connectFunctionsEmulator(functionsInstance, host, port);
59-
}
54+
const functionsEmulatorHost = getDefaultEmulatorHost('functions');
55+
if (functionsEmulatorHost) {
56+
const [ host, port ] = functionsEmulatorHost.split(':');
57+
connectFunctionsEmulator(functionsInstance, host, parseInt(port, 10));
6058
}
6159
return functionsInstance;
6260
}

packages/util/src/defaults.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,14 @@ const getDefaultsFromGlobal = (): FirebaseDefaults|undefined => getGlobal().__FI
1717
const getDefaultsFromEnvVariable = (): FirebaseDefaults|undefined => {
1818
if (typeof process === 'undefined') return;
1919
const fromEnv = process.env.__FIREBASE_DEFAULTS__;
20-
try {
21-
return fromEnv && JSON.parse(fromEnv);
22-
} catch(e) {
23-
console.error(e);
24-
}
20+
return fromEnv && JSON.parse(fromEnv);
2521
};
2622

2723
const getDefaultsFromCookie = (): FirebaseDefaults|undefined => {
2824
if (typeof document === 'undefined') return;
2925
const match = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
30-
if (!match) return;
31-
const decoded = base64Decode(match[1]);
32-
if (!decoded) return;
33-
try {
34-
return JSON.parse(decoded);
35-
} catch(e) {
36-
console.error(e);
37-
}
26+
const decoded = match && base64Decode(match[1]);
27+
return decoded && JSON.parse(decoded);
3828
};
3929

4030
const getDefaults = () => getDefaultsFromGlobal() ||

0 commit comments

Comments
 (0)