在Firebase实例中添加自定义路由 [英] Adding custom routes inside a Firebase instance

查看:33
本文介绍了在Firebase实例中添加自定义路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是Firebase(以及其他JS框架)的新手,并积极阅读文档.

I'm still new to Firebase (as well as other JS frameworks) and actively reading through the documentation.

据我了解,Firebase可以处理基本的CRUD操作(使用API​​库还是直接将主机URL调用到特定路由).在我的应用程序中,我想创建一个个人URL路由来处理一些业务操作,然后从那里调用CRUD操作.

As far as I've read, Firebase can take care of basic CRUD operations (be it using the API libraries or directly calling the host URL to the specific route). In my application, I want to create a personal URL route that will handle some business operations and from there, call the CRUD operations.

我目前想到的是拥有一个中间件",它将处理此自定义URL路由和Firebase API调用.但是,由于它在Firebase实例之外,因此我无法从那里使用其身份验证功能.

What I've currently thought of is for me to have a "middleware" that will handle this custom URL routes and Firebase API calls. But since this is outside of the Firebase instance, I can't use its Authentication feature from there.

我是否可以在Firebase实例中添加这些自定义API调用?我已经事先搜索过,找不到与该主题有关的任何文章.

Is there a way for me to add these custom API calls inside the Firebase instance? I've already searched beforehand and couldn't find any articles regarding the subject.

任何帮助将不胜感激!

推荐答案

我不喜欢在Firebase和用户之间放置中间件.尽管有可能,但是这使事情变得相当复杂,您将很快失去Firebase的一些最大优势(例如实时同步,不托管API的简单性).

I'm not a fan of putting middleware between Firebase and the user. While it is possible, it complicates matters considerable and you'll quickly lose some of Firebase's biggest advantages (e.g. realtime synchronization, the simplicity of not hosting an API).

看看这个经典的博客文章使用Firebase的常见应用程序体系结构.最好的选择可能是选项2,在该选项中,您将数据库用作API/端点,然后运行一个小的进程(例如,节点或JVM)以执行实际操作.这种方法的巨大优势在于,这些工作进程通常比在中间件上运行要简单得多,因为它们不是API端点.

Have a look at this classic blog post on common application architectures with Firebase. Your best bet is likely option 2, where you use the database as your API/endpoint and then run a small (e.g. node or JVM) process to perform the actual operation. A huge advantage of this approach is that these worker processes are often a lot simpler than if they'd run on the middleware, since they are not an API endpoint.

我们的 firebase-queue库是针对这种情况而设计的,但是 Flashligh 也是一个很好的例子.

Our firebase-queue library was made for this type of situation, but Flashligh is also a good example.

这篇关于在Firebase实例中添加自定义路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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