vasanthv / jsonbox

HTTP-based JSON storage.
https://jsonbox.io
MIT License
2.49k stars 171 forks source link

Feature suggestion: Local version with Docker #20

Closed amv closed 5 years ago

amv commented 5 years ago

A local version would remove a lot of demo effects in hackathons when the wifi is laggy, and would also be faster due to no network latencies.

The easy & dirty way would be to create a single container that runs both a mongo server and the node process, but this would make the container very heavy and problems hard to debug.

An alternative route would be to abstract the db layer and allow using something like sqlite3.

And yet another option would be to just provide an in-memory db option for local use. To make this a bit more usable, one might consider adding super simple to understand persistence by making it possible to enable a stdout output in the style of a log that can be piped back to a fresh server to restore the old state.

Example after providing a simple Dockerfile in the repo:

docker build -t jsonbox .
docker run --rm -i -p 80:80 jsonbox >> log.dump
[ do stuff and exit container ]
cat log.dump | docker run --rm -i -p 80:80 jsonbox >> log.dump

The log could look something like this, just outputting a line for each operation:

PUSH box_id/category/xxx { "i was": "inserted" }
PUT box_id/category/xxx { "i was": "updated" }
DELETE box_id/category/xxx 

I personally would prefers the last one as it is by far the simplest to operate and allows storing different states of the db simply by copying the file, but understand if you don't want to add code for doing in-memory db alternative with custom query implementations.

Let me know if any pull requests would be welcome, especially for the last option :)

amv commented 5 years ago

If something like with the log+load is implemented, having the option to dump the contents of a box in the free service in a format that can be ingested by a local version might be a useful addition too. Then one could initially just develop against the free service, but set up a local/offline demo when needed.

This would also act as kind of a backup system in case your service experiences problems at any point.

amv commented 5 years ago

Getting CORS to work with a local version can be a major PITA in some situations though. Usually not a problem for local dev envs, but if you initially develop through a TLS secured remote host using the free service, getting the remotely hosted page to contact something on localhost without a valid TLS cert can cause a lot of gray hairs :(

iambenkay commented 5 years ago

Great idea @amv !

vasanthv commented 5 years ago

@amv currently there is no plan to provide an alternative db store for local envs.

harlev commented 5 years ago

Addressing at least some of the requests with https://github.com/vasanthv/jsonbox/pull/24

vasanthv commented 5 years ago

@harlev have addressed this as part of https://github.com/vasanthv/jsonbox/commit/ff0758e3a35c0fe4926652ae57822bfca2272ea1