Problems with Couchdb cors

I am trying to use jquery.couch.js to perform fist operations in my ember.js application, but I have problems with COS and I don't know what a good solution is.

It seems to me that a couch operating on port 5984 will make it unusable? Why do requests to different ports cause cors problems? And how do OTHER people end up getting a couch for work? I am very confused and do not know how to act.

My couch instance returns this from curl :

 {"couchdb":"Welcome","version":"1.2.0"} 

The code I'm trying unsuccessfully to run is as follows:

 $.couch.urlPrefix = "http://127.0.0.1:5984"; $.couch.login({ name: 'name', password: 'secret' }); 

I modified the urlPrefix part several times for things like localhost , and removed http:// for both versions.

The error she throws is:

 XMLHttpRequest cannot load http://127.0.0.1:5984/_session. Origin http://localhost is not allowed by Access-Control-Allow-Origin. 

Help me! I humbly admit my talkativeness to say this, but how is couchdb even useful if it is built right into the basic functions?

Oh, and I include jquery.couch.js as follows:

 <script src="http://localhost:5984/_utils/script/jquery.couch.js"></script> 

Using this version of jquery:

 jQuery JavaScript Library v1.10.2 

and using jquery migrate due to previous issues:

 <script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script> 

Edit

I just tried adding crossDomain: true, xhrFields: {withCredentials: true} to my login call, but to no avail. The exact error message. I clearly have no basic concept.

0
source share
2 answers

The message you see is for the server, not the client. Changes made to the customer’s call will not, as you have informed, change the result.

In CouchDB 1.4, in particular, CORS support must be explicitly enabled and an expression of origin must be made. However, depending on how you use the CouchDB instance, there are two ways to enable it:

  • Change the setting in local.ini directly and restart your instance, see here for more information: http://wiki.apache.org/couchdb/CORS
  • If you have futon , go to "Settings" and find the parameter there and turn it on, in which case a reboot is not required.

Update

It seems that the CORS section does not always exist by default, in which case just add it yourself.

Hope this helps.

+3
source

For those that use Cookie authentication (rather than password authentication) and reuse the cookie in the Ajax request returned by the CouchDB server, you still need to do this in the $ .ajax () requests for CouchDB:

 xhrFields: {withCredentials: true}, 

Which means that you need to open the jquery.couch.js file that you received from the cache server and manually insert this option into javascript.

CORS did not work for me without doing this on the client side and setting "credentials = true" on the server side.

The original jquery.couch.js, as it is written right now, does not support sending cookies using CORS on the client side, so you need to do this yourself until someone opens a ticket to fix this.

0
source

Source: https://habr.com/ru/post/893676/


All Articles