我如何在Firebase中运行服务器端代码? [英] How would I run server-side code in Firebase?

查看:177
本文介绍了我如何在Firebase中运行服务器端代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能,我想执行一些服务器端验证,但我不知道如何做到这一点?任何建议,我应该看看。没有在文件中如何做到这一点?最好的方法是在Firebase中创建一个待定节点和一个已完成节点,每当客户端需要一个需要服务器验证的操作,让客户端向暂挂节点添加一个条目在服务器端,可以使用Firebase node.js客户端(或者Java SDK)来监听挂起节点上的更改,验证如果验证成功,则将其放入完整节点中,您需要设置安全规则,以便只有服务器代码才能将项添加到完整节点中(例如,通过使用秘密) - 详细了解Firebase安全规则: https://www.firebase.com/docs/security /security-rules.ht ml



如果您的验证相当简单,您可以使用安全规则自己进行验证 - 它们提供简单的字符串/整数/布尔验证。


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?

解决方案

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.

这篇关于我如何在Firebase中运行服务器端代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆