Unable to add CORS authorization to Couchbase Server

We are trying to communicate with Couchbase Server database directly instead of going through sync gateway always. We have a JS web app that is trying to query the database like:

$.ajax({
     url: "xxxx:8093/query/service?statement=select member from `edc` where member.general_info.member_aces_id='11111'",
     responseType: 'json',
     type: 'GET',
     success: function(data) {
              console.log("data: " + JSON.stringify(data));
     },
     error: function(xhr, status, err) {
          console.log("error: " + err + " xhr: " + JSON.stringify(xhr));
     }});

When running this on a VM under the same domain I am getting error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://xxxx:8093/query/service?statement=select%20member%20from%20`edc`%20where%20member.general_info.member_aces_id=‘11111’. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

From documentation I found online, about older versions of Couch, it says to add the CORS configuration to local.ini:

[cors]
methods: GET
origins: *

[httpd]
enable_cors = true

This configuration is not working and to get it to work we have to download and use CORS addons for Firefox which is not an option for production. Please let me know if you need me to clarify any other configurations.

1 Like