Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I run server-side code in Firebase?

I have a function where I want to perform some server-side validations, but I"m not sure how to do this? Any suggestions where I should look. THere is nothing in the documentation of how to do it?

like image 200
Kamilski81 Avatar asked Feb 09 '14 00:02

Kamilski81


People also ask

Is Firebase server side?

The server side of Firebase Cloud Messaging consists of two components: The FCM backend provided by Google. Your app server or other trusted server environment where your server logic runs, such as Cloud Functions for Firebase or other cloud environments managed by Google.

Is Firebase a server side language?

In short, Firebase is a platform that allows you to build web and mobile applications without a server-side programming language.


2 Answers

The best way to do this is to create a "pending" node and a "completed" node in Firebase. Every time the client takes an action that requires server validation, have the client add an entry into the pending node. On the server side, you can use the Firebase node.js client (or Java SDK) to listen for changes on the "pending" node, validate the action, and then put it in the "complete" node if the validation succeeds. You'll need to setup your security rules such that only the server code can add items into the "complete" node (for example, by using the secret) - learn more about the Firebase security rules here: https://www.firebase.com/docs/security/security-rules.html

If your validations are fairly simple to perform, you may be able to do the validation using the security rules themselves - they provide simple string/integer/boolean validation.

like image 171
Anant Avatar answered Sep 23 '22 20:09

Anant


It's late. However, just for someone passing by. Firebase has introduce Cloud Function a month ago. Try to check the official link out. It allow you to put some logics in server side.

https://firebase.google.com/docs/functions/

In my understanding instead of thinking about the communication to server as common Request and Response you need to see it as Database trigger event. You can set up the function that will be called when specific action happen.

like image 27
Boonya Kitpitak Avatar answered Sep 22 '22 20:09

Boonya Kitpitak