EDIT: The reason for this was because in couchDB config under cors, PUT was not enabled. After I enabled this it worked as it should!
I am trying to add a new user to couchDB and it will work fine with postman for an example
I set the headers using admin username and password and then send the following
http://vps.xxxxxxxxx:5984/_users/org.couchdb.user:test
With the following JSON
{"name":"dfbfdb","password":"fbdbfd","roles":[],"type":"user"}
And I get back
{"ok":true,"id":"org.couchdb.user:test","rev":"1-a9925d62c9529ab695ef0e7ff98e9965"}
However when trying to do the same in agular I keep just getting
OPTIONS http://vps.xxxxxx:5984/_users/org.couchdb.user:test2
(index):1 XMLHttpRequest cannot load http://vps.xxxxxx:5984/_users/org.couchdb.user:test2. Invalid HTTP status code 405
The controller I have built to do this is below.
app.controller('signUpController', ['UserService', '$http', '$location',
function(UserService, $http, $location) {
this.user = {
username: this.username,
password: this.password
}
this.register = function() {
var user = {
name: this.user.username,
password: this.user.password,
roles: [],
type: 'user'
}
console.log(user)
$http({
url: "http://vps.xxxxxxx:5984/_users/org.couchdb.user:" + user.name,
method: 'PUT',
withCredentials: true,
headers: {
'Authorization': auth_hash('adminname', 'adminpass')
},
data: user
}).success(function(data, status, headers, config) {
console.log('user added')
}).error(function(data, status, headers, config) {
console.log(angular.toJson(user))
console.log(status)
console.log(headers)
console.log(config)
})
}
}
]);
Does anyone have any idea why it will not work doing it through angular?
Thanks