I'm unable to get PouchDB Cloudant replication to work over a proxy (express/node.js server and node-http-proxy). Would like to achieve this to add access control.
Replication works without proxy:
PouchDB --> Cloudant (https://account:password@account.cloudant.com/testdb
)
Replication fails with proxy:
PouchDB --> express proxy (http://localhost:3000/proxy
) --> Cloudant (https://account:password@account.cloudant.com/testdb
)
error: CustomPouchError
Proxy
const httpProxy = require("http-proxy");
const proxy = httpProxy.createProxyServer();
router.all("/proxy", (req, res, next) => {
proxy.on("proxyReq", (proxyReq, req, res, options) => {
proxyReq.setHeader("Authorization", "Basic: Base64(account:password)")
})
proxy.web(req, res, {
target: "https://account:password@account.cloudant.com/testdb",
secure: false,
changeOrigin: true
});
});
PouchDB
// succeeds without proxy
localDB.replicate
.to("https://account:password@account.cloudant.com/testdb")
.on('error', err => {
console.log('error', err);
});
// fails with proxy
localDB.replicate
.to("http://localhost:3000/proxy")
.on('error', err => {
console.log('error', err);
});
Really stuck on this! Really appreciate any thoughts on what's wrong or how to achieve pouchdb cloudant replication over a proxy. Thank you!