Closed jmdobry closed 8 years ago
I got it to build successfully by replacing __dirname+"/
with "./
, but it looks like Browserify doesn't have a shim for the net
core Node library (it shims most of them), which is used by rethinkdbdash.
@jmdobry -- to be able to send queries from the browser, you need to rely on HTTP instead of TCP -- which is basically this issue: https://github.com/neumino/rethinkdbdash/issues/11
In a browser, the official driver send HTTP queries to localhost:8080/ajax/reql/
with some more data. Note that while it sounds nice, that's not a feature you can use for an actual website since it would require you to export the HTTP port of RethinkDB (so anyone could access the web interface).
Adding support for HTTP is not too hard I think, but just a bit messy.
Fair enough
Perhaps a library akin to minimongo would be more appropriate for browsers. I'd even be happy with the client side version allowing you specify a query
handler which would let you handle queries however you want
// actual api should be something that looks more natural than this
r.setQueryHandler(function (query) {
return sendQueryToBackEndAndReturnPromise(query); // query being a JSON serialized version of any ReQL query after `.run` is called
});
Server side:
app.post('/api/', function (req, res) {
var query = r.reqlFromJSON(req.query);
query.run(); // you would ideally do some security checks on req.query before you unserialize and run it
});
This issue is about a browser directly connecting to RethinkDB via HTTP instead of using simple TCP connections.
If you want a mini-mongo, you can hook https://github.com/neumino/reqlite with rethinkdbdash. Reqlite implements most of the term baring the geo-spatial ones and changefeeds I think.
Ah sorry I misread the issue! If I'm understanding correctly rethink only supports HTTP officially via the endpoint for the admin interface, correct? If that's the case I'd say still have the driver generate whatever queries it wants to execute and let the user define a function that sends the actual request. Opens the door for other transports (web sockets, backend that does some additional security filtering or proxies the request safely to the backend ajax endpoint without exposing the web interface to the world, etc).
I know that's a tall order and really would require making the "transport" a pluggable part of the driver but I think it could lead to some interesting things. Transport being a single function that takes a query and returns a promise for the result. Would even make it easy to add support for weird environments like Chromecast via the message bus API or something
Edit: This all kind of hedges on ReQL being easily serializable/unserializable as JSON, I'm not sure about the the specifics of this but I'd imagine it is
Closing as duplicate of #11
The official driver runs in the browser. Is there any way to get rethinkdbdash to run in the browser, perhaps with Browserify?
Currently I get
'Error: Cannot find module '/node_modules/rethinkdbdash/lib/helper.js'
when requiring rethinkdbdash and building with Browserify.