Running DB couchdb in HTML + Javascript web

I have a website created using HTML and JavaScript maintained by Tomcat.

I need to add a no-SQL database to it, and I'm trying to use Couch DB. I have problems because I understand how the database works, but I have no idea how to connect it to my website.

I use SQL where I just need to make a connection and then send SQL queries. How can I instantiate a connection object for CouchDB and use couchdb.js? Tomcat is currently responding to my cross-domain problem because Tomcat and couchdb are on different ports.

Can someone help me with the base itself?

+4
source share
2 answers

Resource Sharing (CORS) will be implemented only in the next version of CouchDB (v.1.3).

This may be surprising, but you need to understand that these are not the “very basics” of CouchDB:

  • Most CouchApp web application developers serve their Ajax applications from within CouchDB itself (using HTML shows, lists, and attached static pages).
  • Some developers use CouchDB as a simple database in a three-tier architecture.
  • Others send requests to CouchDB from desktop or signed applications (Java, Flash, etc.).

So, sending Ajax requests from code received from external sites was relatively rare.

My recommended tip is to accept one of the most common settings.

If this is definitely not suitable for your case, you can either test the CouchDB development version or use a proxy server so that CouchDB is on the same server as your HTML code (until the next version).

0
source

First, you need to get acquainted with curl, after which you will begin to test your couchdb through the command line. Trying on the same computer on which you installed couchdb.

$ curl localhost:5984 

After that, try accessing from another computer using curl:

 $ curl http://<your_couchdb_server_name_or_ip>:5984/ 

If you cannot, you need to check if there is a firewall on your server that blocks external requests to your server on port 5984.

Now, in order to access your couchdb from an ajax request, you must configure the local.ini file:

 [httpd] enable_cors:true; [cors] credentials:true; mehods:PUT,GET,POST,DELETE,OPTIONS; origins:*; 

Reboot the couch and try again, this should solve your problem.

0
source

All Articles