RethinkDB/Horizo​​n:与 Express 集成:访问 Horizo​​n 数据服务器端? [英] RethinkDB / Horizon: Integration with Express: Access Horizon data server-side?

查看:44
本文介绍了RethinkDB/Horizo​​n:与 Express 集成:访问 Horizo​​n 数据服务器端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Horizo​​n.io Github 上有一个快速集成的例子,如下所示:Horizo​​n express 服务器示例

There is an example of express integration on the Horizon.io Github as shown here: Horizon express server example

我理解这个例子所展示的内容:如果你有一个现有的 Express 服务器,你可以添加一个地平线服务器,它公开一个路由客户端,以便他们可以通过 websockets 连接到地平线服务器.

I understand what this example is showing: if you have an existing Express server you can add a horizon server, which exposes a route client-side so they can connect to horizon server via websockets.

但是,服务器的 express 部分是否也可以访问 Horizo​​n 中的集合? 例如,执行本地身份验证、CRON 作业或具有 API 端点等操作接受 PUT/POST 请求.

However, is there is any way for the express part of the server to also access the collections in Horizon? For example, to do things like local authentication, CRON jobs, or have API endpoints that accept PUT/POST requests.

据我所知,与 Horizo​​n 正在使用的 RethinkDB 数据库的直接连接并不是那么有用,因为名为 Fusion 的库动态设置表上的元数据,以便获得 Horizo​​n 用于的类似 Firebase 的行为.

From what I understand, a direct connection to the RethinkDB database Horizon is using is not that useful, because of a library named Fusion that is dynamically setting metadata on the tables in order to get Firebase-like behavior that Horizon is used for.

如何访问 Horizo​​n 数据服务器端?

推荐答案

要访问 Horizo​​n 的集合,您可以使用 @horizo​​n/client.

To access the collections of Horizon you can use the @horizon/client.

npm install --save  @horizon/client

在服务器端代码中:

const Horizon = require("@horizon/client/dist/horizon");
const horizon = Horizon();

然后您可以使用 Horizo​​n API:http://horizo​​n.io/api/horizo​​n/ 用于诸如连接、身份验证和用户之类的内容;然后使用集合 API:http://horizo​​n.io/api/collection/ 获取访问权限客户端访问的相同集合.

And then you can use the Horizon API:http://horizon.io/api/horizon/ for things such as connection, Auth, and users; then use the collection API: http://horizon.io/api/collection/ for getting access to the same collections that the client accesses.

这篇关于RethinkDB/Horizo​​n:与 Express 集成:访问 Horizo​​n 数据服务器端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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