5

Was briefly mentioned here, but right now I'm at the point where I've connected my GCP project to Firebase, set up a custom domain under Firebase hosting, but on the functions page of the Firebase dashboard, there doesn't seem to be a way to set the vanity URL on a cloud function.

My firebase.json (at the root of my project) looks like :

{
    "hosting": {
        "public": "public",
        "rewrites": [
            { "source": "/helloWorld", "function": "helloWorld" },
            { "source": "/progress", "function": "progress" }
        ]
    }
}

enter image description here

sdfsdf
  • 5,052
  • 9
  • 42
  • 75

1 Answers1

11

To associate a vanity domain with your Cloud Functions, you need to associate them with Firebase Hosting. See the documentation on connecting the two.

Say you have a Cloud Function https://us-central1-<your-project-id>.cloudfunctions.net/bigben.

After making this connection the function will also be available on https://<your-project-id>.firebaseapp.com/bigben.

If you also connect a custom domain with Firebase Hosting, the function will also be available on https://<your-custom-domain>.com/bigben.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • When I visit the url where my cloud function should be, I get a web page that says "404 Page Not Found The specified file was not found on this website. Please check the URL for mistakes and try again. Why am I seeing this? This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory." – sdfsdf Jul 22 '18 at 05:59
  • Please edit your question to include the redirects from your `firebase.json` and to show how you've set up your custom domain. – Frank van Puffelen Jul 22 '18 at 13:29
  • Edited. Initially, my firebase.json was an empty object. Not sure how to redeploy the Firebase Hosting. I redeployed the cloud function on GCP by pressing edit and then saving (doesn't update when I push to git?), but the function deploy doesn't reflect in the Firebase console. – sdfsdf Jul 23 '18 at 02:47
  • 1
    The custom domain only works for Cloud Functions deployed through Firebase's CLI (i.e. with `firebase deploy`). There is no other way for Firebase to know what functions you have and how to rewrite the URLs to them. – Frank van Puffelen Jul 23 '18 at 03:53
  • @FrankvanPuffelen do you know if there is a way to use path variables when redirecting to a Firebase Function? i.e. `source: ":path*", function: ":path"`. The docs show using a wildcard to redirect all paths to a single function, and they show using path variables when redirecting to other paths, but, in my testing, it seems like you cannot simply redirect `example.com/:functionName` to the proper function. Instead, you either need to individually create redirects for each function (not practical) or eliminate individual functions and create a single express app function. – John Mar 13 '19 at 12:05
  • Does not work at all for me with custom domain or `projectid.firebaseapp.com` –  Jun 06 '19 at 09:23
  • It is important to say that it only works for GET requests, as the "redirect" configuration is a real 301 redirection, and not a Google internal mapping... – jeanmatthieud Apr 08 '21 at 07:54