RethinkDB / Horizon: Integration with Express: Access Horizon data server-side?

强颜欢笑 提交于 2019-12-01 04:38:36

问题


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

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.

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.

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.

How can I access Horizon data server-side?


回答1:


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

npm install --save  @horizon/client

in server side code:

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

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.




回答2:


You need to create express/koa/hapi server, where you include horizon/server and provide your own implementation for custom API endpoints.

Read more here: http://horizon.io/docs/embed/



来源:https://stackoverflow.com/questions/37402526/rethinkdb-horizon-integration-with-express-access-horizon-data-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!