Reputation: 337
I'd like to create a website hosted by Firebase Hosting, which can post/put/get data from a Firebase Database. Google's example to connect Hosting to a Database isn't very helpful to me though, because it doesn't give any indication of how to fire a cloud function AFTER the page has loaded (the example fires a cloud function whenever you go to a specific url and fires when that page loads).
The most similar SO post I could find was this one, which appears to be able to interact with a database after the page loads like I want, my difference is that I want the interaction to be server-side (I want as little information about how the data is stored as possible to be shown).
I'm thinking if I can fire a cloud function after the page has loaded (when a user hit's a save button), that cloud function can interact with the database through an API to save the information.
In my searching I couldn't find very much information about connecting Firebase like this, is this possible/logical?
Upvotes: 1
Views: 509
Reputation: 317808
It sounds like all you need to do is create an HTTP trigger, then call that from a XMLHTTPRequest or similar. You can do that whenever you want from the page that's currently showing in the browser.
Cloud Functions code don't need to be interacting with the database via a REST interface. They should just be using the Admin SDK instead, which is far easier and faster. There are a lot of official samples that illustrate this.
Upvotes: 3