0

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

||||||
0

In CouchDB config e.g

http://localhost:5984/_utils/config.html

Make sure the 'PUT' method is available to use in CORS.

Because I was updating the database over a different domain this is the reason I was getting a 405 error.

||||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.