colinskow / pouch-mirror Goto Github PK
View Code? Open in Web Editor NEWHelps you maintain a local mirror of any CouchDB database for lightning-fast reads and secure writes.
License: MIT License
Helps you maintain a local mirror of any CouchDB database for lightning-fast reads and secure writes.
License: MIT License
Currently, the pouch-mirror API doesn't include destroy
event. Can I take a PR to add one? The idea is to destroy localDB instance. This is useful in scenarios where multiple users share one browser environment and when a user logs-off, it is prudent to delete any local DB containing private information. As pouch-mirror abstracts the localDB instance, exposing a destroy method will make it easy to delete the localDB.
Pouch-mirror uses a remote-first strategy for any edit calls. This ensures that there's only a single source of truth in a multi-client-single-server scenario and also helps with conflict resolution.
But in cases where the client interactions are heavy, the server-first approach may lead to a slower turn-around, and may not work well in cases of flaky network connectivity.
Would you plan to revisit this project to bake-in a local-first strategy? If you are too busy now, I can fork this project and add one.
For a local-first approach, I think the following interactions should be acceptable -
Thoughts!?
Hi Colin,
This is totally a non-issue with library. I needed your help in debugging a problem I am facing and as I didn't have your email, I am reaching out to you here.
To prevent having to expose CouchDB endpoint to my application users, I tried to add a simple reverse-proxy using request
in my express app -
```
// Bind /db to couch DB backend
var DATABASE_URL = 'http://localhost:5984';
// middleware itself, preceding any parsers
app.use(function(req, res, next){
var proxy_path = req.path.match(/^\/db(.*)$/);
if(proxy_path){
var db_url = DATABASE_URL + proxy_path[1];
console.log("db_url: " + db_url);
req.pipe(request({
uri: db_url,
method: req.method
})).pipe(res);
} else {
next();
}
});
Also, I added dbServer > publicURL: 'http://localhost:8080/db/' in superlogin config, so that the private DB urls come mapped to the `/db` endpoint. Things went good this far. However, when I ran the application, the replication initiated by pouch-mirror went amok and never ended. The calls trough the proxy are going through, however somehow the replication is screwed up. The private DB size ballooned very quickly from mere 8.1k to 1MB in no time.
Do you have experience with a setup like this? Would be great if you can give me any pointers.
Thanks!
Hi Colin,
Aside from Superlogin, I am also trying to integrate pouch-mirror into my application to sync with a logged in user's remote private DB (CouchDB 1.6.1) with an IndexedDB based in-browser PouchDB instance.
My setup is something like this -
Front end - React, Reflux, superlogin-client and pouch-mirror.
Server - Express, Superlogin
DB - Couch 1.6.1 (brand new, Admin Party enabled).
Right now, when I am using pouch-mirror, its able to write docs to the user's remoteDB correctly, when the sync has not finished. However, the sync never finishes. The replication process keeps on throwing 'ETIMEDOUT' exception (caught in the error
event handler in startLiveReplication
). Due to this issue, the replication to local DB _never _ completes and the application keeps on using remoteDB only.
Using Fiddler, I saw that the request to the Remote URL look like this -
GET http://localhost:5984/<remoteDBname>/_changes?timeout=25000&style=all_docs&feed=longpoll&heartbeat=10000&since=3&limit=100 HTTP/1.1
Host: localhost:5984
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
Authorization: Basic Wl9zQ0dKZFNSa2FmNm9wOUcxQ0xwZzp0MWlqbUJCQlNJbUMyMVpfV1U1bjln
Referer: http://localhost:8080/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Its on this request where pouch-mirror receives the time-out exception. I take it that this is supposed to be a long-polling request and wonder whether this exception is expected.
I looked into the code of startLiveReplication
and saw that there's a bind to uptodate
event which is supposed to handle sync completion as its this place where pouch-mirror switches remoteDB with localDB. However, this enevt never gets invoked. Also, I didn't notice this event in the PouchDB replication docs. There's a complete
event listed but per the documentation, for a live
replication, the complete event will never be invoked unless the sync is cancelled.
Thoughts!?
PS: My entire development stack is on a single machine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.