How to rewrites to firebase hosting - firebase

I have tried to work on this tutorial which is about creating Cloud Run environment and serving a page on Firebase Hosting.
https://firebase.google.com/docs/hosting/cloud-run#python
The Cloud Run part works as it says on the page, but Firebase Hosting part is not working for me. It get 404 error when I access the PROJECT_ID.web.app/ and PROJECT_ID.firebaseapp.com/
I updated the Firebase CLI version to make it the latest version.
"hosting": {
"public": "public", // I need to add this since I got an error without specify public dir
"rewrites": [ {
"source": "**",
"run": {
"serviceId": "helloworld", // "service name" (from when you deployed the container image)
"region": "us-central1" // optional (if omitted, default is us-central1)
}
} ]
}
Does anyone have the same issue as well?
Thanks!

I am wondering if you have missed a step in the set up stage. There is a helpful guide that includes the steps for implementation you might want to have a look at.
You can also test your container locally with Docker to rule out any obvious issues first. If you need to install Docker you can follow this guide.
To run your container locally you can do:
PORT=8080 && \
docker run -p 9090:${PORT} -e PORT=${PORT} gcr.io/myproject/my-image:latest
Replace myproject/my-image:latest to the project where the container image is stored on Google Cloud Platform
The PORT environment variable specifies the port your application will use to listen for HTTP or HTTPS requests. This is a requirement from the Container Runtime Contract. In this example, we use port 8080.
http://localhost:9090

Related

Can't access google cloud run service from Firebase Hosting

Basically what the title states. I'll be replacing the service name with 'xyzservice' and the region name with 'xyzregion' but everything else is exactly as is.
I have a firebase hosting app where I want to access a service running on Google Cloud Run. As per documentation, I'm using a rewrite rule:
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/api/**",
"run": {
"serviceId": xyzservice,
"region": xyzregion
}
},
{
"source": "**",
"function": "app"
}
]
}
}
I can confirm that I see xyzservice is part of my project when I run gcloud beta run services list
Despite this I keep getting this error:
HTTP Error: 400, Cloud Run service xyzservice does not exist in region xyzregion in this project.
I can't seem to find any information about this error online. Anyone know how I might resolve this?
Thanks in advance!
Same here. Are you using a region other than us-central1? In my case, changing the region from asia-northeast1 to us-central1 works. I'm not sure if it's a spec change or a failure.
Firebase Hosting deployments with rewrites to Cloud Run services located in europe-west1 were broken between 24. - 26. August 2020. I reached out to Google Firebase support. They acknowledged the bug and told me on the morning of 26. August that the issue is now resolved. The configuration above should now perfectly work (as long as the service actually exists).
(It was Firebase Support Case 00080862)

Auth0 and Next.js deployed to Vercel: Location header error

I started with this sample repo: https://github.com/vercel/next.js/tree/canary/examples/auth0
My current repo: https://github.com/rebeccapeltz/next-auth-app-1
Login/Logout work fine locally. When I deploy to Vercel and logout I get this message in the browser:
Invalid character in header content ["Location"]
I've double checked the Auth0 env variables and they seem correct. Login works fine on Vercel. Can't figure out how to troubleshoot the header Location value that is causing the problem.
Nothing much going on yet and easy to reproduce: https://next-auth-app-1.now.sh/
Solved this by removing all env variables added to the Vercel online application settings. Then added the secrets using the now CLI now secrets add and deployed the app by setting up other env variables in now.json and using now --prod. Working OK now. For further external env secrets and references, I'm wondering if t's better to add them via now.json or to use the online settings GUI. One thing that wasn't clear is that when you add variables with now add secrets you need to prefix the value in the now.json with #. Kind of like accessing bash env variables with $. So after adding secrets my now.json looks like this
{
"build": {
"env": {
"AUTH0_DOMAIN": "<name of auth0 domain>",
"AUTH0_CLIENT_ID": "<what you get from auth0>",
"AUTH0_CLIENT_SECRET": "#auth0_client_secret",
"REDIRECT_URI": "<name of vercel app or domain name>/api/callback",
"POST_LOGOUT_REDIRECT_URI": "<name of vercel app>/",
"SESSION_COOKIE_SECRET": "#session_cookie_secret"
}
}
}
Should you add all env using secrets add and then just reference by name in the now.json? not sure.

Firebase Hosting rewrite doesn't redirect to Google Cloud Run

I am setting up a redirect(rewrite) with my firebase hosting so that I can call an api that is running from google cloud run here.
I have tried changing the rewrite string from "/api/**" (should catch all things to page.com/api/** and send that to the function). deleted the index.html and swapped to "**" to capture ALL paths including index. Nothing has worked so far.
My hosting firebase.json is setup like so, is there something wrong with this?
{
"hosting": {
"public": "dist/public",
"ignore": ["firebase.json", "**.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"run": {
"serviceId": "next-js-base-api",
"region": "us-central1"
}
}
]
}
}
I also tried with normal redirects to another page, this does not work, what determines when the firebase.json settings begin to propagate and work?
Update
I tried running the hosting emulator and with a modified rewrite "source": "/api/**" which had the following results. Navigating to /api returns non crash (doesn't redirect) with output in browser of cannot GET /api navigating to api/wkapi (a sub directory that is caught by the api endpoint) returns an unexpected error in the browser and
Error: Unable to find a matching rewriter for {"source":"/api/**","run":{"serviceId":"next-js-base-api","region":"us-central1"}}
in the console.
Make sure to update to the latest version of your Firebase CLI by running:
npm install -g firebase-tools#latest
This will enable you to rewrite to cloud run instances as you are trying to do.
Actually, I ran this just now and, looking at the logs of the deployed cloud-run helloworld container, found that custom-domain/helloworld is actually mapping onto container-domain/helloworld instead of simply mapping to container-domain/. To fix this, I had to add an additional app.get rule to my original Node.js program:
app.get('/helloworld', (req, res) => {
And then calling custom-domain/helloworld worked.
If all the above answers don't help you, the fix that worked for me was:
Look in the public directory in your project that firebase hosting uses.
Delete the index.html file that firebase created when going through
the firebase init steps.
After deleting the generated index.html file, it was able to run my cloud run containers with rewrites.
In my case, the cause for this was misspelling function in the firebase.json file, i,e:
"rewrites": [
{
"source": "**",
"function": "ngssr" // I had spelled this as "functions" (extra s)
}
]

Firebase Serve Error

I am new to firebase and am trying to make a simple app that utilizes user authentication. At this point in the project I am trying to run firebase on a local server using CLI commands.
I have set up firebase init and firebase deploy. When I type firebase serve on my project folder i get the response,
"an unexpected error has occurred".
Below i am attaching the contents of my firebase-debug.log file. Any help would be appreciated. Thanks
command requires scopes:
["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase",...
[debug] [2017-06-11T17:09:09.607Z] > authorizing via signed-in user
TypeError: Cannot read property 'public' of undefined
Look in your firebase.json file, which you should have in the directory where you're running firebase serve. It should look something like this:
{
"hosting": {
"public": "app",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
If it doesn't have that "hosting" key, then you'll get that Cannot read property 'public' of undefined error because firebase serve tries to access .hosting.public.
I faced this issue today, I ran it with --debug and found out that I've installed npm/node as sudo user, running following:
firebase serve
was giving me this error:
Error: An unexpected error has occurred.
When I ran it with sudo, I was able to deploy hosting and functions locally:
sudo firebase serve --debug --only hosting,functions
1) create a folder called "public" and put your files inside.
2) edit the firebase.json and just write this:
{
"hosting": {
"public": "public"
}
}
This appears to be a bug - that ideally should be resolved with Firebase Init. I have logged a support ticket with Firebase, and would encourage others to do so as well.
I think you may have skipped an initialization step by accident (I did the same thing on my first run-through)
Try this (from your same project directory):
1) firebase init
2) When prompted for which services you'll need make sure that Database AND Hosting options have their markers highlighted green (tab to Hosting with the spacebar). It's easy to select just database and let it run its configuration and assume it configures all of the bulleted options below it if you do not watch closely because the stdout info isn't very clear. Now hit Enter
3) Accept the default database settings as you probably did before, and when asked "What do you want to use as your public directory? (public)", hit Enter.
At this point you should be good to go spin up a local firebase web server...
4) try 'firebase serve', hit Enter, and you should get a verification that hosting files are being served from /public
Hope this helps. Good luck.
As for me the error is (--debug attr)
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/firebase-tools/node_modules/#google-cloud/functions-emulator/logs'
So the solution will be to run with sudo

Deploying Telescope App to Amazon EC2

What am I doing wrong? I'm trying to deploy my Telescope app. I'm using this to do that: https://github.com/arunoda/meteor-up. It gives me an error when I try to deploy using Mup. Here's my mup.json config file:
{
// Server authentication info
"servers": [
{
"host": "52.25.228.14",
"username": "ec2-user",
//"password": "password"
// or pem file (ssh based authentication)
"pem": "~/Documents/appname/appname.pem"
}
],
// Install MongoDB in the server, does not destroy local MongoDB on future setup
"setupMongo": true,
// WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
"setupNode": true,
// WARNING: If nodeVersion omitted will setup 0.10.36 by default. Do not use v, only version number.
"nodeVersion": "0.10.36",
// Install PhantomJS in the server
"setupPhantom": true,
// Show a progress bar during the upload of the bundle to the server.
// Might cause an error in some rare cases if set to true, for instance in Shippable CI
"enableUploadProgressBar": true,
// Application name (No spaces)
"appName": "appname",
// Location of app (local directory)
"app": "~/Documents/appname/Telescope",
// Configure environment
"env": {
"ROOT_URL": "ec2-52-25-228-14.us-west-2.compute.amazonaws.com"
},
// Meteor Up checks if the app comes online just after the deployment
// before mup checks that, it will wait for no. of seconds configured below
"deployCheckWaitTime": 15
}
Common pitfalls :
Are sure you ran mup setup before deploying ?
Try using a relative path to setup the app location, ie replace ~/Documents/appname/Telescope by . if your mup.json is located at the root of your Telescope instance.
I did run mup setup, did use http://, and tried many times to get it to connect/deploy.
I gave up and just went with a Wordpress theme and am customizing it how I want it. The other way was way too complicated. It didn't allow me to do what I wanted in a timely manner. Thanks for trying to help though guys.

Resources