• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

How To Alias Cloud Functions In Firebase

Firebase · August 6, 2017

Firebase Cloud Functions are fantastic, but the URL that you get to run them isn’t so nice. You’ll get given a URL that looks like the following when you create some cloud functions:

https://us-central1-demoapp.cloudfunctions.net/functionName

If you are wanting to use Firebase to build an API for your application for example (like I wanted to), then you would probably prefer your URL looks like this:

https://myapp.com/functionName

Fortunately, you can. The only downside is you have to use Firebase hosting if you want to be able to alias your functions to your name. If you’re self-hosting your own site somewhere else and using Firebase, then you can’t alias cloud functions.

To alias cloud functions, open up your firebase.json file and inside of the hosting and rewrites section add in your rule. My example showcases an API endpoint which gets sent to a Firebase cloud function called api which handles the request.

{
    "database": {
        "rules": "database.rules.json"
    },
    "hosting": {
        "public": "public",
        "rewrites": [
            { "source":"/api/**", "function":"api" },
            {
                "source": "**",
                "destination": "/index.html"
            }
        ]
    }
}

In my instance, I have a single page application so I have created a wildcard rewrite to send all requests to the index.html file so my Javascript framework can take over.

All you have to remember is source and function where source is your URL pattern (which supports wildcards and matchers) and function is the name of your created function inside of functions/index.js.

I highly recommend installing and using Express to handle your routing needs inside of cloud functions if you’re wanting to work with aliases, especially for Firebase driven API’s.

In a future article I’ll show you how you can create an API using Firebase and alias the functions.

Dwayne

Leave a Reply Cancel reply

0 Comments
Inline Feedbacks
View all comments

Primary Sidebar

Popular

  • I Joined Truth Social Using a VPN and Editing Some HTML to Bypass the Phone Verification
  • Testing Event Listeners In Jest (Without Using A Library)
  • How To Get The Hash of A File In Node.js
  • Thoughts on the Flipper Zero
  • Waiting for an Element to Exist With JavaScript
  • Handling Errors with the Fetch API
  • How To Get Last 4 Digits of A Credit Card Number in Javascript
  • How To Paginate An Array In Javascript
  • Wild Natural Deodorant Review
  • How To Install Eufy Security Cameras Without Drilling or Using Screws

Recent Comments

  • CJ on Microsoft Modern Wireless Headset Review
  • Dwayne on Microsoft Modern Wireless Headset Review
  • CJ on Microsoft Modern Wireless Headset Review
  • john on Microsoft Modern Wireless Headset Review
  • Dwayne on Why You Should Be Using globalThis Instead of Window In Your Javascript Code

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz