0

I am using Angular to connect to a server running CouchDB that I have set-up. When ever I run the code I get the error:

"XMLHttpRequest cannot load http://ip:5984/_all_dbs. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://morris-tibet.codio.io' is therefore not allowed access."

I have set-up the origins and cannot understand what the problem could be.

Here is the code I am using to connect:

myApp.controller('OverviewCtrl', ['$http',
    function($http) {
        var self = this;
        self.dbNames = [];
        $http({
            url: 'http://ip:5984/_all_dbs',
            method: 'GET'
        }).
        success(function(data, status, headers, config) {
            self.dbNames = data;
            console.log(self.dbNames);
        }).
        error(function(data, status, headers, config) {
            self.dbNames = ['Something wrong with your code!', ''];
            console.log(self.dbNames);
        })
    }
]);

In the code the ip address has been replaced for security reasons.

EDIT:

I was told it may be an issue with my CORS, here is an image showing my cors for the server:

Cors

hudsond7
  • 666
  • 8
  • 25
  • You need to allow CORS. Check out http://stackoverflow.com/questions/23823010/how-to-enable-cors-in-angularjs – connorbode Dec 08 '14 at 13:49
  • They are already allowed I think, I will post an image. – hudsond7 Dec 08 '14 at 13:53
  • Did you set `$httpProvider.defaults.allowXDomain`? – connorbode Dec 08 '14 at 13:55
  • How would I go about doing this? – hudsond7 Dec 08 '14 at 13:56
  • Im not familiar with couchdb but there is likely a cors whitelist somewhere that you'll need to allow your origin from. http://wiki.apache.org/couchdb/CORS – connorbode Dec 08 '14 at 13:59
  • @connorbode I have checked my config files and everything seems to be correct already. Not sure why this is not working. Could it be something to do with my bind address? – hudsond7 Dec 08 '14 at 14:08
  • [origins cannot be * while credentials is true](http://docs.couchdb.org/en/latest/config/http.html#cors). Also make sure that Origin header is really got sent by your client. – Kxepal Dec 08 '14 at 14:40

0 Answers0