I have to make an offline application that sync with another online app when it can.
I developped the offline app using PouchDB. I create this app thanks to the github repo create-react-app. This app is running at localhost:3000. In this app, I create and manage a little DB named "patientDB"
I manage the db with the classical put method like we can see in the documentation :
var db = new PouchDB('patientDB')
db.put({
_id: 'dave@gmail.com',
name: 'David',
age: 69
});
With the developpement tool for chrome given by PouchDb, i can see that the DB is working like i want (the documents are created):
The other application is another React application with a node server. During the developpement, this app is running at localhost:8080. In this app I try to fetch all the docs contained in the "patientDB" with the following code :
const db = new PouchDB('patientDB', { skip_setup: true });
db.info()
.then(() => {
console.log("DBFOUND")
db.allDocs({include_docs: true})
.then(function (result) {
console.log("RESULT" , result)
}).catch(function (err) {
console.log("NOPE")
console.log(err);
});
})
My problem is that I can't get the "patientDB" created with the offline app in the online app. When I do a var db = new PouchDB ('patientDB') it create a new and empty db because it can't find a db which is already present...
I use google chrome to run all my application so I thought that the dbs could be shared.
However I did little and very simple tests with two html files:
First.html which initialize a new db with a doc
Second.html which read the db create in First.html
In this case, I can fetch the doc created with First.html in Second.hmtl even if the are two separated "website".
I think that the application which run at a localhost are like isolated of the rest of the application even if, like I said before, i use the same browser for all my applications...
I don't know what to do or i don't know if it's even possible to do what I want to do... If someone have an idea for me, I would be pleased. Thank you all :)
Aucun commentaire:
Enregistrer un commentaire