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?
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.