Firebase function local dev react
There's a way to handle CORS requests in firebase cloud function, but for local development it makes mrore sense to setup your Create React App to be able to handle the functions locally as follows.
1
firebase.functions().useFunctionsEmulator('http://localhost:4001')
Copied!
in context
1
import firebase from "firebase/app";
2
import "firebase/firestore";
3
import "firebase/auth";
4
import "firebase/storage";
5
import "firebase/functions";
6
​
7
const firebaseConfig = {
8
apiKey: process.env.REACT_APP_API_KEY,
9
authDomain: process.env.REACT_APP_AUTH_DOMAIN,
10
databaseURL: process.env.REACT_APP_DATABASE_URL,
11
projectId: process.env.REACT_APP_PROJECT_ID,
12
storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
13
messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID,
14
appId: process.env.REACT_APP_APP_ID,
15
measurementId: process.env.REACT_APP_MEASUREMENT_ID
16
};
17
​
18
// Initialize Firebase
19
firebase.initializeApp(firebaseConfig);
20
​
21
export const db = firebase.firestore();
22
export const functions = firebase.functions();
23
// https://stackoverflow.com/questions/50884534/how-to-test-functions-https-oncall-firebase-cloud-functions-locally
24
firebase.functions().useFunctionsEmulator('http://localhost:4001')
25
export default firebase;
Copied!
Last modified 2yr ago
Copy link