How to use Firebase to handle automatic server-side computing?

Perhaps my question should be reformulated as follows: how do I reorganize these behaviors into CRUD, what is Firebase superior to?

I get CRUD to work well. I also see how the Firebase declarative security model allows me to provide proper server-side security where it should exist.

Say I have a subscription service. Each time a person subscribes to a service, they need to automatically add the “appropriate” line item added to their account. In simple words:

/users/john /services/goodstuff 

So, john can register for goodstuff , I could let him in for 30 days without payment, but he will remind him when 30 days expire, "hey, you need to pay or lose your goodstuff subscription."

With server-side content, I would POST before /services/goodstuff/members , for example, have a part of the POST handler, adding a "you should" position to my john account, ensuring that no one can join goodstuff without designating it as.

In a Firebase BaaS application, where these server logics do not exist, how will I reorganize the application to get the same effective behavior?

+8
firebase
source share
1 answer

Update (March 10, 2017) . Although the architecture described below is still valid and can be used to integrate Firebase with any existing infrastructure, Firebase has just released Cloud Functions for Firebase , which allows you to run JavaScript functions on Google servers in response to Firebase events (such as database changes data, user login and more).

One potential solution (untested, sorry, but this should be the right idea):

 { "rules": { "users": { "$user": { /* When they create their user record, they must write a 'due' that's * within the next 30 days. */ ".write": "!data.exists() && newData.child('due').isNumber() && newData.child('due').val() < now + (30*24*60*60*1000)" } }, "services": "$service": { /* Must be authenticated and due date must not be passed. */ ".read": "auth != null && now < root.child('users/' + auth.id + '/due).val()" } } } } 

This will require that when someone first logs on to the network and initializes their users / record, they will have to write down the payment date within the next 30 days. And then, when you get access to any service, this date will be checked if it did not pass.

However, another option is to simply deploy a tiny backend service to handle such business logic. Firebase is protected, stored and synchronized. But if you have complex business logic, you might consider deploying a tiny backend process. Firebase has REST api , as well as Node.JS and JVM , so it’s very easy to run native code that integrates with Firebase.

+6
source share

All Articles