Skip to content

Provide "real-time" websocket and REST CRUD transports for RethinkDB backed services using Horizon.

License

Notifications You must be signed in to change notification settings

ubergarm/stack-in-a-box

Repository files navigation

stack-in-a-box

This stack is built on:

  • Caddy 1 - reverse proxy and JWT auth for static assets and admin interface
  • RethinkDB 2 - "real-time" database
  • Horizon 3 - "real-time" javascript client and server interface for RethinkDB
  • Express 4 - add REST endpoints through Horizon client on server side
  • Vue 5 - front end framework

Purpose

The goal of this project is to provide all the parts necessary to create a "real-time" web-app while still providing good old REST endpoints to the same data.

This project is a proof of concept based on this Horizon issue

There may be better ways to do this kind of thing as it is still evolving:

  1. A feathers-horizon 6 might do the trick if someone writes it.
  2. Can Redux provide Horizon across multiple transports?
  3. Horizon Plugins?

This still leaves other questions like:

  1. Should my async tasks access the database directly through ReQL?
  2. Can I rely on change-feeds and ditch message queues?
  3. If I dog-food my APIs then I can never use ReQL and that stinks...
  4. What about HTTP/2 SSE transports?

Requirements

  • docker
  • docker-compose > v1.6 to support version: '2' docker-compose.yml format

Get Started

# cone this repo
git clone https://github.com/ubergarm/stack-in-a-box
cd stack-in-a-box
# build docker images
docker-compose build
# install rest services dependencies
docker run --rm -it -v $PWD/rest:/app \
           --entrypoint=/bin/sh \
           ubergarm/horizon -c "npm install"
# fixup permissions
sudo chown -R $UID:$UID ./rest

You may need to apply a patch 7 for Horizon version 1.1.3:

# check your horizon version
docker run --rm -it ubergarm/horizon version
# if it is 1.1.3 then do the next step
sed -e "/require('imports?this/ s/^#*/\/\//" -i \
    ./rest/node_modules/@horizon/client/lib/util/fetch.js

Now you're ready to run!

Usage

NOTE: docker-config.yml defaults will attempt to bind to your Docker hosts public network iterface on ports 80 and 443.

# bring up the stack
docker-compose up

Now you can do a few things:

  1. RethinkDB admin interface
  2. Static Files
  3. Realtime Chat Demo
  4. REST interface

Use the REST interface:

# GET some data
curl http://localhost/messages
# POST some data
curl -H 'Content-Type: application/json' -d '{"text":"hello"}' http://localhost/messages
# TODO
# JWT example
curl -H "Authorization: Bearer MY_TOKEN" http://localhost/messages

Horizon CLI

An example of initializing a Horizon app.

docker run --rm -it -v `pwd`:/app ubergarm/horizon init realtime
sudo chown -R $UID:$UID ./realtime

TODO

  • Caddy basic config and static files
  • RethinkDB admin ui behind proxy
  • Horizon chat app working behind proxy
  • Express route behind proxy exposing Horizon client through REST
  • GET/POST example for REST API CRUD
  • Authentication
  • Authorization mapping JWT claims to Horizon users
  • Configure permissions running horizon without --dev
  • Secure RethinkDB admin ui with JWT auth
  • Full CRUD support
  • REST CRUD Schema enforcment middleware
  • Maintain a Horizon client connection pool server side?
  • Volume mount .caddy folder to save ACME certs between restarts.
  • Test for websockets and HTTP/2 proper behavior over TLS

Issues

  • You need custom builds of Caddy to support sweet addons like JWT auth.
  • messages REST service doesn't return on first call. Hit it twice.

References

About

Provide "real-time" websocket and REST CRUD transports for RethinkDB backed services using Horizon.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published