Skip to content

Commit

Permalink
Cleanup & functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels committed Sep 17, 2022
1 parent 8294d2d commit 777c206
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
12 changes: 5 additions & 7 deletions packages/functions/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
httpsCallable as _httpsCallable,
httpsCallableFromURL as _httpsCallableFromURL
} from './service';
import { getModularInstance } from '@firebase/util';
import { getModularInstance, getDefaultEmulatorHost } from '@firebase/util';

export * from './public-types';

Expand All @@ -51,12 +51,10 @@ export function getFunctions(
const functionsInstance = functionsProvider.getImmediate({
identifier: regionOrCustomDomain
});
if (app.name === '[DEFAULT]' || app.name.startsWith('authenticated-context:')) {
const functionsEmulatorHost = (globalThis as any).__FUNCTIONS_EMULATOR_HOST__;
if (functionsEmulatorHost) {
const [ host, port ] = functionsEmulatorHost.split(':');
connectFunctionsEmulator(functionsInstance, host, port);
}
const functionsEmulatorHost = getDefaultEmulatorHost('functions');
if (functionsEmulatorHost) {
const [ host, port ] = functionsEmulatorHost.split(':');
connectFunctionsEmulator(functionsInstance, host, parseInt(port, 10));
}
return functionsInstance;
}
Expand Down
16 changes: 3 additions & 13 deletions packages/util/src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,14 @@ const getDefaultsFromGlobal = (): FirebaseDefaults|undefined => getGlobal().__FI
const getDefaultsFromEnvVariable = (): FirebaseDefaults|undefined => {
if (typeof process === 'undefined') return;
const fromEnv = process.env.__FIREBASE_DEFAULTS__;
try {
return fromEnv && JSON.parse(fromEnv);
} catch(e) {
console.error(e);
}
return fromEnv && JSON.parse(fromEnv);
};

const getDefaultsFromCookie = (): FirebaseDefaults|undefined => {
if (typeof document === 'undefined') return;
const match = document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/);
if (!match) return;
const decoded = base64Decode(match[1]);
if (!decoded) return;
try {
return JSON.parse(decoded);
} catch(e) {
console.error(e);
}
const decoded = match && base64Decode(match[1]);
return decoded && JSON.parse(decoded);
};

const getDefaults = () => getDefaultsFromGlobal() ||
Expand Down

0 comments on commit 777c206

Please sign in to comment.