forked from timetospare/find-food-camden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fire.js
55 lines (46 loc) · 1.29 KB
/
fire.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
54
55
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/storage';
import 'firebase/functions';
import { BUILD_LEVEL as buildlevel } from './config.json';
export const BUILD_LEVEL =
process.env.NODE_ENV === 'production' ? 'production' : buildlevel;
const REGION = 'europe-west1';
const DEV_PORT = 5001;
const productionConfig = {
apiKey: <<apiKey>>,
authDomain: <<domain>>,
storageBucket: <<bucket>>,
projectId: <<projectId>>,
};
const stagingConfig = {
apiKey: <<apiKey>>,
authDomain: <<domain>>,
storageBucket: <<bucket>>,
projectId: <<projectId>>,
};
let config;
if (process.env.NODE_ENV === 'production') {
config = productionConfig;
} else if (BUILD_LEVEL === 'staging') {
config = stagingConfig;
} else if (BUILD_LEVEL === 'dev') {
config = stagingConfig;
} else if (BUILD_LEVEL === 'production') {
config = productionConfig;
}
const fire = !firebase.apps.length
? firebase.initializeApp(config)
: firebase.app();
const fireFunctions = fire.functions(REGION);
const fireDb = fire.firestore();
if (BUILD_LEVEL === 'dev') {
fireDb.settings({
host: 'localhost:8080',
ssl: false,
});
fireFunctions.useFunctionsEmulator(`http://localhost:${DEV_PORT}`);
}
fire.functions = () => fireFunctions;
fire.firestore = () => fireDb;
export default fire;