-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase.js
54 lines (46 loc) · 1.79 KB
/
firebase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Low level initialization of the Firebase SDK
import { initializeApp } from 'firebase/app';
import { getStorage, ref} from 'firebase/storage';
// figure out which environment we're running in. By default, we'll let rollup modify the following variable
// so that it correctly holds the value 'dev' or 'prod':
let ENV_NAME = (import.meta.env.MODE == 'development') ? 'dev' : 'prod';
let inBuild = ENV_NAME == 'prod';
// allow forcing prod from the command line via VITE_FORCE_PROD=1
if (ENV_NAME == 'dev' && import.meta.env.VITE_FORCE_PROD == '1')
{
console.log('WARNING: overriding dev env and hitting prod resources due to env var!')
ENV_NAME = 'prod';
}
// if we are in dev, allow hitting prod resources via ?prod=1 on the URL
if (ENV_NAME == 'dev')
{
let params = Object.fromEntries(new URLSearchParams(location.search));
if (params.prod == '1')
{
console.log('WARNING: overriding dev env and hitting prod resources due to URL param!')
ENV_NAME = 'prod';
}
}
// set official global vars
export const IN_PROD = (ENV_NAME == 'prod');
export const IN_DEV = !IN_PROD;
export const IN_BUILD = inBuild;
window.IN_DEV = IN_DEV;
window.IN_PROD = IN_PROD;
window.IN_BUILD = IN_BUILD;
export let app = null; // the Firebase app instance
export let storage = null;
export let API_URL = ''; // the API to use to call cloud functions
export function Init(firebaseConfig, devFuncURL, prodFuncURL)
{
if (!firebaseConfig)
console.log('ERROR: firebaseConfig required for firebase.Init');
app = initializeApp(firebaseConfig);
storage = getStorage();
if (devFuncURL && IN_DEV)
API_URL = devFuncURL;
else if (prodFuncURL && IN_PROD)
API_URL = prodFuncURL;
else
console.log('WARNING: no API URL specified for current environment', ENV_NAME);
}