I usually have my Firebase projects organized with a separate repo for the web app, manager portal, and cloud functions. Because the web app and manager portal use the same firebase project I keep the cloud functions in their own separate repo. So 3 different repos/projects using the same Firebase project.
I'm testing out how to use the Firebase Local Emulator Suite with this set up but it doesn't appear I can start the emulator for the cloud functions within my Cloud Function project, then use the emulator in my web app project for firestore and calling the functions, and then the same for my manager portal project. This will cause conflicts and cause them all to run on different ports and the functions project won't have access to the firestore emulator and the web app and manager won't have access to the functions emulator.
Is there a way to make this work? The only way I can see how is to have my manager app, web app, and functions all in the same project/repo...which I don't want to do for a bunch of reasons.
Currently I just set up a 2nd Staging project on firebase and use that for testing but would love to be able to do all of this locally. Any help is much appreciated.
I was just struggling with the same today and it turns out it is as simple as:
in your main project, start your emulators as usual with e.g. firebase emulators:start --only firestore
in your dependent projects, do not try to start the firestore emulator, but instead initialise the firebase config as follows:
import * as express from 'express'
import * as admin from 'firebase-admin'
import * as functions from 'firebase-functions'
admin.initializeApp(functions.config().firebase)
var db = admin.firestore()
if (process.env.NODE_ENV !== 'production') {
db.settings({
host: "localhost:8080",
ssl: false
})
}
You can use symbolic links in your project directories to create a "fake" functions directory. Then you can run a single instance of the emulator.
Running two instances of the emulator can cause several weird bugs as it is not recommended.
On windows:
mklink /D "R:\my-cloud-functions-proj\functions" "R:\my-web-app\functions"
Related
I'm currently using json-server repo to emulate my back-end db and server for a prototype. To use/start json-server, I need to execute npm run json:server.
I've deployed my project to firebase but can't find a way to access a cmd or run that command from my own git-bash.
Is there any way of doing so or firebase doesn't allow to run commands on their end?
If you want to run small Node.js snippets on Firebase, have a look at the integration between Firebase Hosting and Cloud Functions.
Also see the Firebase documentation on what can you host on Firebase? and the overview documentation for running micro-services on Firebase Hosting and Cloud Functions.
I have two projects for dev and prod. I want to be able to run a script to copy dev config to prod.
Firebase Remote Config has an API for programatically updating Remote Config. But as far as I can tell, you need to init admin with a project-specific service account. It seems like I would need two admin instances, but I'm not sure that's possible?
I'm wondering if someone has done this before and has an example script. Thanks!
See docs:
https://firebase.google.com/docs/remote-config/automate-rc
There is no Firebase Admin SDK for Flutter, so you'll have to implement this on a different platform that is supported. For a list of these platforms and instructions on setting it up, see the documentation on adding Firebase to a server.
For these platforms that the Firebase Admin SDK targets, you can create multiple instances of the FirebaseApp class, and initialize each of them with different credentials and project configuration. For examples of how to do this, see the documentation on initializing multiple apps.
This page explains:
Note: The FIREBASE_CONFIG environment variable is included automatically in Cloud Functions for Firebase functions that were deployed via the Firebase CLI.
Can we get access to the same FIREBASE_CONFIG environment variable in Cloud Run environment? If yes, how?
If no, please give instructions on setting firebase-admin initializeApp and firebase initializeApp for authentication on Cloud Run.
Should we save the serviceAccount and firebase-config in our project and import them? If so, what are the best practices for doing that? When working on an open-source project, we should put these files in .gitignore. Then how should we push them to the Cloud Run environment using gcloud CLI?
When I first setup my firebase project and ran firebase init I didn't think i'd host a site. So I didn't check the hosting on setup.
And so i have an ios project with the following folder structure:
myproject:
- ios (xcode code)
- firebase
- functions
- index.js (i have cloud functions already deployed from here)
If I run firebase init again can i just select "hosting" so that a public folder is added without overwriting everything in the functions folder?
You can tell the CLI to only initialize hosting with:
firebase init hosting
That way your other settings will remain unmodified.
I've built an app with polymer 2.0 and polymerfire and deployed it into firebase hosting. This part is smooth.
But I wanted to maintain all my cloud functions as separate modules / separate projects and deploy them independently into firebase hosting. As per the Google IO 2017 talks, it is advised to go microservice style for the cloud functions.
The problem I am facing:
Whenever I deploy an individual module, it erases all the previously deployed cloud functions. Meaning firebase deploy from a project with only firebase functions enabled, will erase all the other cloud functions and deploy the ones declared in this project.
In a nutshell, it looks like I need to create a single monolith with the complete web application, all the cloud functions all in one single fat project and deploy the whole thing. This defeats the point of being microservice style!
Please advise if I am missing something important in the whole setup procedure?
You can deploy/undeploy individual functions with the Firebase tools/CLI version 3.8 or higher by specifying what function(s) to update: firebase deploy --only functions:function1,function2. It will still deploy all the code in your project, since the CLI doesn't "know" what file(s) are needed for each specific function. But it will then only update the function(s) that you specify.