Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase and backend logic

I am parse.com user, and now I look for another service. How can I write back end logic to firebase?

let say I want to validate all the values on server side, or trigger things. I thought about one solution, but I want to know the recommended way.

I think to

  1. create nodejs server, that uses express.
  2. create middlewares to handle the logic.
  3. send rest request from the app, that triggers the middlewares
  4. use the nodejs sdk of firebase to update the values according to the params of the http request.
  5. And implement on the app firebase handler that listen to changes

enter image description here

their something simpler? In parse I used cloud code, I want that the logic will not be on the client side but on a server side.

like image 975
Alon Avatar asked Feb 12 '16 10:02

Alon


People also ask

Can Firebase be used for backend?

Firebase is a Backend-as-a-Service (BaaS) app development platform that provides hosted backend services such as a realtime database, cloud storage, authentication, crash reporting, machine learning, remote configuration, and hosting for your static files.

Why is Firebase used as backend?

Firebase provides the best back-end server, great database and analytics solution, and useful integrations with other Google products. Most of all, users like that it's free to use and has affordable subscription options. A wisely designed backend solution guarantees project scalability and data security.

Is Firebase frontend or backend?

Firebase provides a ready-made backend system that frontend developer can use to hook their GUI without waiting for the backend to be ready.

Can we use Firebase as backend for website?

Firebase is a fully managed backend service that gives you best-in-class infrastructure for your web apps, handling everything from user authentication and server scaling, right through to crash analytics and a reliable testing environment. Just set it and forget it.


1 Answers

Update (March 10, 2017): While the architecture I outline below is still valid and can be used to combine Firebase with any existing infrastructure, Firebase just released Cloud Functions for Firebase, which allows you to run JavaScript functions on Google's servers in response to Firebase events (such as database changes, users signing in and much more).


The common architectures of Firebase applications are pretty well-defined in this blog post Where does Firebase fit in your app?.

The architecture you propose is closest to architecture 3, where your client-side code talks both directly to Firebase and to your node.js server directly.

I also highly recommend that you consider option 2, where all interaction between clients and server runs through Firebase. A great example of this type of architecture is the Flashlight search integration. Clients write their search queries into the Firebase database. The server listens for such requests, executes the query and writes the response back to the database. The client waits for that response.

A simple outline for this server could be:

var ref = new Firebase('https://yours.firebaseio.com/searches'); ref.child('requests').on('child_added', function(requestSnapshot) {      // TODO: execute your operation for the request      var responseRef = ref.child('responses').child(requestSnapshot.key());     responseRef.set(result, function(error) {         if (!error) {             // remove the request, since we've handled it             requestSnapshot.ref().remove();         }     }); }) 

With this last approach the client never directly talks to your server, which removes all kind of potential problems that you have to worry about. For this reason I sometimes refer to them as "bots", instead of servers.

like image 124
Frank van Puffelen Avatar answered Nov 06 '22 00:11

Frank van Puffelen