Cloud functions routes (aka rewrites) without using Firebase Hosting

1,351 views
Skip to first unread message

Ido Feins

unread,
Jan 26, 2018, 10:13:25 AM1/26/18
to Firebase Google Group
Hi,

I have a project using Firestore and Cloud Functions.

In this project I have two functions "createUser" and "refreshUserData".
By default upon deploy firebase hosts the functions at URLs such as https://<domain-projectid>.cloudfunctions.net/createUser.
I don't want to use these URLs (camel case suits for JavaScript methods, less for API endpoints) and want to use more REST-y URLs such as:
I know that I can achieve that by using Firebase hosting and using "rewrites" as detailed in the "Direct Hosting requests to your function" section in this guide.
However I don't want to use Firebase Hosting as I don't have any static content that I want to deploy.
So I have two questions in that regard:

  1. Is there a way to define routes (e.g. "/user/refresh") that map to cloud functions without using Firebase Hosting?
  2. If not, then why is the functionality of providing routes to cloud functions tied to a product for static content hosting?
    This seems like a very common use case where someone creates a cloud function and want to provide a custom URL for it.
Thanks,
Ido


Michael Bleigh

unread,
Jan 26, 2018, 12:22:59 PM1/26/18
to fireba...@googlegroups.com

I’d encourage you to consider Firebase Hosting to be a general-purpose web hosting platform, not just for static content. You could deploy nothing but a 404.html and a firebase.json with a function rewrite and that would be a completely appropriate use of Firebase Hosting.

That being said, Cloud Functions does have the ability to do basic routing without connecting to Firebase Hosting. Each Cloud Functions URL will accept any request that contains itself as a prefix. So if I have the URL:

https://us-central1-my-project.cloudfunctions.net/someFunction

I can add a slash and additional routing after it:

https://us-central1-my-project.cloudfunctions.net/someFunction/users/annie

Look at the req.url in the function handler to see the path after the function name. You can even write standard Express apps with routes that work against these URL patterns.

Hope that helps!


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a24a7d62-9c4e-4d7b-8fb2-9a53fcca40bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ido Feins

unread,
Jan 28, 2018, 11:03:34 AM1/28/18
to Firebase Google Group
Thanks Michael for the quick reply :)
I'll probably go with the Firebase Hosting solution.

Ido

Felix Halim

unread,
Jul 17, 2018, 4:29:19 PM7/17/18
to fireba...@googlegroups.com
The max Firebase Functions duration is 540 seconds.
When Firebase Hosting is used to host the functions, it's subject to 60 seconds timeout.

What is the rationale behind the 60 seconds timeout restriction?
Can exception be made for hosted Firebase Function?

Felix Halim
Reply all
Reply to author
Forward
0 new messages