How to use Firebase Serve without triggering my Firebase https Function - firebase

I have created a Firebase Function to server side render my website for SEO purposes.
However now when I use firebase serve or firebase serve --except functions the function is still triggered.
This means the only way I can test is by deploying and updating my https function.
Is there a way to test locally without triggering my function?

You can serve functions locally with the command below;
firebase serve --only functions
This would serve your functions from localhost:5000. If you would like to serve this local version you can also use NGROK and test it with your front-end.

Related

Firebase Callable Functions and ExpressJs App living on the same project

I am building a web site using ExpressJS + EJS for rendering server side content on Firebase Cloud Functions. At the index.js, located right under the functions folder, I have setup my express app with routes, middlewares, EJS views, and finally exported the express app variable via functions.https.onRequest so that all requests coming from firebase hosting could be rewritten to the ExpressJS app.
The challange here starts when one of the client pages (rendered at the server side) needs to invoke a callable function on the same functions project. How to serve callable functions and expressjs endpoints on the same project?
Putting all the code in the index.js might be a way to solve the issue, however, it will quickly become insane to manage all callable functions endpoints along with express endpoints in the same index.js file.
I have also seen that FCF now supports working with different codebases, but there isn't much information or any example in the documentation to follow along.
What would be your solution?

Can Firebase Hosting redirect to a Cloud Run tag?

We use cloud run to generate preview URLs as well as production URLs. We use github actions to generate a tagged cloud run deployment of our python backend based on the PR (e.g. pr-12---abcxyz.web.app) and generate a front-end cloud run deployment for our Vue app. Our load balancer on GCP allows us to ensure that requests going to our LB are directed to our production Cloud Run deploys (e.g. tagged with prod)
We want to make use of firebase hosting for its edge deployment capabilities, but it looks like we cannot have firebase redirect to a specific tag, only the entire cloud run instance.
If it is not possible to redirect to a cloud run tag, how would you recommend we set up preview URLs with firebase + python backend? We want to make sure that the preview URL uses the front-end and back-end code from our monorepo so that we never have questions about what is running where.

How does Firebase set a Cloud Function's default Authentication?

I have a web app which I've deployed to multiple Firebase projects (i.e. dev, staging, production). It uses Cloud Functions for Firebase for its back-end functionality.
Recently, after deploying to a new environment, I started getting a CORS error for one of the functions. After some searching I found that the Authentication settings in the Cloud Functions panel can affect this, and in this case making the Function accessible to allUsers solved my CORS issue.
While in the Functions console, I noticed that most, but not all, of my Firebase functions had Authentication set to "Allow unauthenticated" by default. What was strange, however, is that in different environments (i.e. dev vs staging) a function might be set to allow unauthenticated, but in others would not (even though I never manually altered any of these settings).
Essentially, my question is, how are these settings determined? I only every deployed my functions via firebase deploy or firebase deploy --only functions. What is the expected behavior here? Are Cloud Functions deployed via Firebase expected to be set to "Allow unauthenticated" by default, and those that aren't simply experienced some kind of error during deployment?
Are Cloud Functions deployed via Firebase expected to be set to "Allow unauthenticated" by default?
Yes, that's what the Firebase CLI does, and that allows the function to be invoked without Google IAM. That's the expectation for code that backs a mobile or web app, since they won't use IAM.
That setting has nothing to do with CORS. CORS is fully under your control in the code of the function.

How to access firebase-functions environment configuration from Cloud Run

I'm migrating a Firebase Function to Cloud Run. Everything is working as expected so far, including the Firebase Hosting link (which is great!). I'm just not sure how I should read the environment variables I've configured for this project (via https://firebase.google.com/docs/functions/config-env).
You'll have to find a different way to configure Cloud Run. You won't be able to access your environment variables set for Cloud Functions when deployed with the Firebase CLI. Those variables are only accessible for code running in Cloud Functions that uses the "firebase-functions" module.
Instead, you should set your Cloud Run environment with gcloud as documented here.

How I can deploy Firebase function on heroku for google asistant

I have created a simple function for google assistant (dialogflow) for firebase function with the next structure:
functions/
node_module/
index.js
package-lock.json
package.json
firebase.json
How I can deploy this function (webhook) on Heroku for using it in Google actions for google home (dialogflow). The main problem with firebase is that the firebase doesn't allow sen HTTP request from functions in a free account.
You can only deploy code written for Cloud Functions to the Cloud Functions service itself. The code absolutely depends on the Cloud Functions scalable infrastructure to work the way that it does.

Resources