I cannot get Coucbase Lite _replicate to work with Cordova (PhoneGap), using the Ionic Framework (AngularJS) and $http call. $http always results in a 400 BAD REQUEST from Couchbase Lite. I’m uncertain about the proper config settings, nor how to debug the error at a deeper level (yet).
Due to my existing codebase, I want to use $http.post with Couchbase Lite. My Couchbase server and Sync Gateway are working together fine and are configured to use bucket shadowing between the sync bucket and primary server bucket.
DETAILS:
CBL ERROR REASON: {“data”:{“status”:400,“error”:“bad_request”},“status”:400,“config”:{“method”:“POST”,“transformRequest”:[null],“transformResponse”:[null],“url”:“http://lite.couchbase./_replicate”,“data”:{“target”:”app-cbl",“source”:“10.60.0.100/sync_gateway/”,“continuous”:“true”},“contentType”:“application/json”,“headers”:{“Accept”:“application/json, text/plain, /”,“Content-Type”:“application/json;charset=utf-8”}},“statusText”:"Bad Request”}
//
// Cordova code running on iOS
//
this.startReplication = function () {
var deferred = $q.defer();
// -- I have tried multiple configs, using both $http and $http.post, and also revised source / target --
// -- This config is the closest to working, but results in a 400 error. --
var config = {
method: 'POST',
url: "http://lite.couchbase./_replicate",
data: {
target: ’app-cbl’,
source: ’10.60.0.100/sync_gateway/',
continuous: 'true'
},
contentType: 'application/json'
}
$http(config).then(function (result) {
console.log('### CBL SUCCESS RESULT: ' + JSON.stringify(result));
deferred.resolve(result);
}, function (reason) {
console.log('### CBL ERROR REASON: ' + JSON.stringify(reason));
deferred.reject(reason);
}).catch(function (err) {
console.log('### CBL CATCH ERROR: ' + JSON.stringify(err));
deferred.reject(err);
})
return deferred.promise;
}
I have also tried different URLs for the sync gateway, but still get the same 400 error so I assume the error is originating locally on the iOS side.
Thank you for any assistance.