App Engine and Firebase Hosting in One Domain - firebase

I have a custom domain (travelbox.id) that connected to Firebase Hosting already. I also have an App Engine application to serve as my API. I want to host the App Engine application on api-dev.travelbox.id. I mapped the custom domain to App Engine following this docs but domain connection to Firebase Hosting stop working. If you access api-dev.travelbox.id it is connected to App Engine. But if you access travelbox.id it doesn't connected to Firebase Hosting.
Is that impossible to achieve what I want?

I had the same issue and contacted Google Cloud support, here's their answer:
App Engine doesn't need to have the A records on the root domain if
you are only serving from a subdomain. App Engine should work
properly for you with just the one CNAME on subdomain.example.com.

I found the solution myself, here you go!
On the fourth step in this docs, i didn't add A records, just add AAAA records. Suprisingly, it works! :D

Related

Setup Organization/Company subdomain in firebase without setting up DNS

I have an app hosted on firebase that is deployed to my Cloud Domains.
let's say https://example.com
Now, for every custom domain or subdomain I want to add to firebase, I require to manually setup the DNS on of my Cloud Domain with the required records.
But, I would like to create workspace for organization in my app (like for example Jira does doing myOrg.atlassian.com).
So the result would be
organization.example.com
organization2.example.com
Is it possible to allow this without having to manually set DNS for each organization joining our app ?
Would it be possible to dynamically create and setup on firebase and link those subdomain to my cloud domain ?
Thank you
Currently, there is no way to add custom domains automatically. Firebase Hosting doesn’t have such an API through which it can be done. Also I couldn’t find a workaround to dynamically achieve this feature. So the only way to do this is to go to the Firebase Console and set it up as described here. You can go through this similar StackOverFlow thread to know more about it.

Firebase hosting / auth / cloudstore hosted on a server in Australia

I have a requirement to host a web app that uses Firebase services on a server physically located in Australia. Can anyone tell me if this is possible and if so is there any documentation available around this? I would be using Firebase Hosting / Auth / Firestore - all would need to be hosted in Australia.
Firebase Hosting is hosted on a global CDN network. You can't restrict where it is server or accessed from.
Firebase Authentication data is also stored globally, outside of your control.
I'm not sure what Cloudstore is, but given the above two answers you might already want to look at alternative products.

Configuring a reverse-proxy-like Firebase Hosting solution

This is what I currently have
domain.com -> website A with its own firebase host (domain.firebase.com)
me.domain.com -> website B with its own firebase host (domain-me.firebase.com)
This wasn't hard to set up, just multiple sub-domains redirecting to different Firebase hosts. Now, what I want, is a reverse proxy takes a request and has the option of routing traffic to various servers while keeping the client URL only on the main domain of domain.com. I'm not sure if this is possible specifically with Firebase, as there are tons of NGINX implementation examples, But basically, I want this:
domain.com/ -> website A with its own firebase host (domain.firebase.com)
domain.com/me -> website B with its own firebase host (domain-me.firebase.com)
Firebase has very intricate redirect options, but redirects also overwrites the client URL. So with a redirect, the client will see domain-me.firebase.com instead of domain.com/me, which isn't what I want.
As far as I've figured, I can use Firebase Cloud functions to serve as a middleware, and have it serve either site as needed. However, this introduces a lot of latency as both Cloud functions and Firebase hosted websites have warm-up times from cold starts.
It's totally fine to not give me a complete and detailed answer, I really just want to know if this is possible to begin with, and where I can find relevant resources. Thanks!
To answer my own question and building on Doug's answer of using Cloud Run. There is a quick and painless way to set up a reverse-proxy-like implementation with 2 apps. To do this:
1) Build both apps and have them in separate folders, such as folder A and folder B. You only need the build folders of the apps, you don't need the source code.
2) Create a new Express app at the root of folders A and B.
3) Have Express manage routes using app.get and serve files back using res.sendFile.
4) Containerize the entire Express app following Google's tutorial here, you can ignore the sample application since your new Express app is the application.
5) Upload to Cloud Run as a new service. Keep in mind that while the Google tuts don't specify, you will need to give your user permission to upload to the storage bucket. You will need the command
gsutil iam ch user:[user]:objectViewer gs://us.artifacts.[project-name].appspot.com
Also make sure to switch to the current project using command gcloud config set project [project-name] if you have multiple projects.
6) Use Google domain mapping to map to your root domain, so domain.com.
You must use domain mapping as the URL used by Cloud Run is ephemeral...'cause it's serverless.
Your folder structure should be something like
my-awesome-project
index.js <- Express app and Docker entry point
/package.json <- for your Express app
/A
/B
/Dockerfile
/node_modules
Example router would be
app.get('/me/*', (req,res) =>{
res.sendFile(path.join(__dirname+'/B/index.html'));
});
app.get('/*', (req,res) =>{
res.sendFile(path.join(__dirname+'/A/index.html'));
});
Setting your apps up on subdomains instead works pretty much the same way. Containerize each individual app using step 4, then map each domain separately using Google Domain Mapping.
Integration with Cloud Functions and Cloud Run are pretty much your only options here. There's nothing in the config that will let you proxy your requests directly to other endpoints other than indirectly through HTTP redirects.

Securing Firebase Hosting web site with a GCP VPN

I am working on a platform (www.dashboard.example.com) that has an admin site (www.admin.example.com). Each site is hosted on a different Google Firebase Hosting Project.
I want only certain people to be able to access the admin site. After some consideration, I found an IPSec VPN to be the best solution for me.
I also found that GCP offers a VPN service, but from what I can tell, it seems to only work with google compute engines.
Is there a way to attach a Google VPN to a Firebase Hosted site?
There is no way to attach a Cloud VPN to a Firebase Hosting Project.
In GCP the correct way to restrict the access to your web server/application is by using firewall rules/App Engine's firewall and Cloud VPC/VPN service.
Your approach should be to put a proxy by configuring a Google Compute Engine1 in between your gateway service and your Firebase Hosting Project.
Another approach would be to use Cloud Storage2, as a static website3. You can then create an HTTPS Load Balancer based on Backend Bucket4. With this you can benefit from the advantages of using Load Balancer and also using Cloud VPN.
If you are interested in authentication with Firebase and App Engine I suggest to check the following link 2.

Secure a firebase hosting link to only be accessible from a specific ip

I am using angular 4 angularfire 2 and firebase in an web app. I am conditionate to use firebase as a backend service and because the app has to only be used inside the office i am wondering if there is any way i can configure some firebase rules or anything to make the app not work or be shown from another ip than the office ip. Please leave any kind of way i can do it. Thanks in advance!
There is currently no way to restrict access to a site deployed to Firebase Hosting. It will always be accessible from anywhere in the world that is not blocked by some other firewall.

Resources