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?
Related
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.
I have a back-end server built using firebase cloud functions and I'm trying to test it and have a shareable test link without having to deploy to the live channel.
I found this https://firebase.google.com/docs/hosting/test-preview-deploy#preview-channels but when I follow the instructions, it only deploys the static public folder. So any changes I make to the back-end have no effect. I can use the back-end using the preview URL but it's always the same version as the live build.
Am I missing something? Or is preview channels for static content only?
That's correct, preview channels currently only support static content + Firebase Hosting configuration. One way to work around this (admittedly not ideal), is to deploy the old and new versions of your Cloud Function as separate functions (e.g. app and appV2) and change the preview channel to point to the different function.
I am new to firebase and cloud functions, please try to help.
I have an app that uses cloud function to call external APIs. As my app is now live and consuming those APIs through cloud functions. I have to develop new features in my app using Dev environment without disturbing Live functions.
There are two different URLs of external APIs for Dev and Production.
For example:
Dev = demoapi.example.com/someapi
Live = api.example.com/someapi
How can i only upload cloud functions to dev environment without disturbing LIVE app.
Do i have to write copy of each function in my index file? Or is there any other way? becuase there are around 20 functions.
Both Dev and Production DBs/Projects are different in firebase. But i can only pay for one blaze plan (as cloud function requires blaze plan to make external requests) so i want to use one project for functions.
Making copy of each function is not the right choice.
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.
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.