Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live replication not working between two servers #430

Open
hadrien-toma opened this issue Mar 3, 2020 · 2 comments
Open

Live replication not working between two servers #430

hadrien-toma opened this issue Mar 3, 2020 · 2 comments

Comments

@hadrien-toma
Copy link

Hello folks,

While running the following two pouchdb-servers, the initial state of localhost:4444/local database is well replicated to localhost:5555/local but then, when I add a document in localhost:4444/local via fauxton, it is not replicated... Does someone have an idea why?

  • localhost:4444:
import * as express from 'express';
import * as expressPouchDB from 'express-pouchdb';
import * as PouchDBStatic from 'pouchdb';

const envs = {
	admin: {
		password: 'cloud',
		username: 'cloud'
	},
	databases: {
		local: {
			auth: {
				username: 'cloud',
				password: 'cloud'
			},
			subPath: '.dbs/cloud/'
		}
	},
	port: 4444,
	subPath: '.dbs/cloud/'
};
const prefix = `${process.env.INIT_CWD}/${envs.subPath}`;

const app = express();

const pouchdbOnFs = PouchDBStatic.defaults({ prefix });
const expressPouchdbOptions = {
	configPath: `${prefix}/config.json`,
	logPath: `${prefix}/log.txt`
};
const pouchdbOnFsHandle = expressPouchDB(pouchdbOnFs, expressPouchdbOptions);

pouchdbOnFsHandle.couchConfig.set('admins', envs.admin.username, envs.admin.password, (error) => {
	console.log('cloud', "couchConfig.set('admins', ...)", { error });
});

app.use('', pouchdbOnFsHandle);

const localDatabase = new PouchDBStatic<any>('local', {
	prefix: envs.databases['local'].subPath,
	auth: envs.databases['local'].auth
});

localDatabase
	.put<any>({ _id: 'en', flag: '🇬🇧' })
	.then(({ id, ok, rev }) => {
		console.log('cloud', 'localDatabase', 'put', 'then', { _id: id, ok, rev });
	})
	.catch((error) => {
		console.error('localDatabase', 'put', 'catch', { error });
	});

const server = app.listen(envs.port);

server.on('error', (error) => {
	console.log('cloud', 'server', 'error', { error });
});
  • localhost:5555:
import * as express from 'express';
import * as expressPouchDB from 'express-pouchdb';
import * as PouchDBStatic from 'pouchdb';

const envs = {
	admin: {
		password: 'device',
		username: 'device'
	},
	databases: {
		local: {
			auth: {
				username: 'device',
				password: 'device'
			},
			subPath: '.dbs/device/'
		},
		remote: {
			name: 'http://localhost:4444/local',
			options: {
				auth: {
					username: 'cloud',
					password: 'cloud'
				}
			}
		}
	},
	port: 5555,
	subPath: '.dbs/device/'
};
const prefix = `${process.env.INIT_CWD}/${envs.subPath}`;

const app = express();

const pouchdbOnFs = PouchDBStatic.defaults({ prefix });
const expressPouchdbOptions = {
	configPath: `${prefix}/config.json`,
	logPath: `${prefix}/log.txt`
};
const pouchdbOnFsHandle = expressPouchDB(pouchdbOnFs, expressPouchdbOptions);

pouchdbOnFsHandle.couchConfig.set('admins', envs.admin.username, envs.admin.password, (error) => {
	console.log('device', "couchConfig.set('admins', ...)", { error });
});

app.use('', pouchdbOnFsHandle);

const databases: { [key: string]: PouchDB.Database<any> } = {};

databases['local'] = new PouchDBStatic<any>('local', {
	prefix: envs.databases['local'].subPath
});
databases['remote'] = new PouchDBStatic<any>(envs.databases['remote'].name, envs.databases['remote'].options);

databases['local'].replicate.from(databases['remote'], { live: true, retry: true });

const server = app.listen(envs.port);

server.on('error', (error) => {
	console.log('device', 'server', 'error', { error });
});
@BillMeyerRSA
Copy link

Hello folks,

While running the following two pouchdb-servers, the initial state of localhost:4444/local database is well replicated to localhost:5555/local but then, when I add a document in localhost:4444/local via fauxton, it is not replicated... Does someone have an idea why?

  • localhost:4444:
import * as express from 'express';
import * as expressPouchDB from 'express-pouchdb';
import * as PouchDBStatic from 'pouchdb';

const envs = {
	admin: {
		password: 'cloud',
		username: 'cloud'
	},
	databases: {
		local: {
			auth: {
				username: 'cloud',
				password: 'cloud'
			},
			subPath: '.dbs/cloud/'
		}
	},
	port: 4444,
	subPath: '.dbs/cloud/'
};
const prefix = `${process.env.INIT_CWD}/${envs.subPath}`;

const app = express();

const pouchdbOnFs = PouchDBStatic.defaults({ prefix });
const expressPouchdbOptions = {
	configPath: `${prefix}/config.json`,
	logPath: `${prefix}/log.txt`
};
const pouchdbOnFsHandle = expressPouchDB(pouchdbOnFs, expressPouchdbOptions);

pouchdbOnFsHandle.couchConfig.set('admins', envs.admin.username, envs.admin.password, (error) => {
	console.log('cloud', "couchConfig.set('admins', ...)", { error });
});

app.use('', pouchdbOnFsHandle);

const localDatabase = new PouchDBStatic<any>('local', {
	prefix: envs.databases['local'].subPath,
	auth: envs.databases['local'].auth
});

localDatabase
	.put<any>({ _id: 'en', flag: '🇬🇧' })
	.then(({ id, ok, rev }) => {
		console.log('cloud', 'localDatabase', 'put', 'then', { _id: id, ok, rev });
	})
	.catch((error) => {
		console.error('localDatabase', 'put', 'catch', { error });
	});

const server = app.listen(envs.port);

server.on('error', (error) => {
	console.log('cloud', 'server', 'error', { error });
});
  • localhost:5555:
import * as express from 'express';
import * as expressPouchDB from 'express-pouchdb';
import * as PouchDBStatic from 'pouchdb';

const envs = {
	admin: {
		password: 'device',
		username: 'device'
	},
	databases: {
		local: {
			auth: {
				username: 'device',
				password: 'device'
			},
			subPath: '.dbs/device/'
		},
		remote: {
			name: 'http://localhost:4444/local',
			options: {
				auth: {
					username: 'cloud',
					password: 'cloud'
				}
			}
		}
	},
	port: 5555,
	subPath: '.dbs/device/'
};
const prefix = `${process.env.INIT_CWD}/${envs.subPath}`;

const app = express();

const pouchdbOnFs = PouchDBStatic.defaults({ prefix });
const expressPouchdbOptions = {
	configPath: `${prefix}/config.json`,
	logPath: `${prefix}/log.txt`
};
const pouchdbOnFsHandle = expressPouchDB(pouchdbOnFs, expressPouchdbOptions);

pouchdbOnFsHandle.couchConfig.set('admins', envs.admin.username, envs.admin.password, (error) => {
	console.log('device', "couchConfig.set('admins', ...)", { error });
});

app.use('', pouchdbOnFsHandle);

const databases: { [key: string]: PouchDB.Database<any> } = {};

databases['local'] = new PouchDBStatic<any>('local', {
	prefix: envs.databases['local'].subPath
});
databases['remote'] = new PouchDBStatic<any>(envs.databases['remote'].name, envs.databases['remote'].options);

databases['local'].replicate.from(databases['remote'], { live: true, retry: true });

const server = app.listen(envs.port);

server.on('error', (error) => {
	console.log('device', 'server', 'error', { error });
});

Were you able to figure out how to do this? Having similar issues.

@hadrien-toma
Copy link
Author

Nop, I am still blocked on this part...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants