couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Cottlehuber <>
Subject Re: Having troubles with rewrites
Date Tue, 08 Oct 2013 19:01:46 GMT
>On Oct 8, 2013, at 5:01 AM, "Mark Deibert" > wrote:
>Hey Stanley :-)
>Thanks for the advice and for a normal, CouchDB only setup, you're info is
>correct. However, with a Couchapp, it works a bit different. You have to
>setup the rewrites.js(json) file in your Couchapp directory structure and
>then it pushes the rewrite property to a specific doc in CouchDB. So the
>rewrites property is on the correct document. I _think_ my problem is in my
>paths. Either the vhosts, or in the rewrite "from" and/or the "to". I was
>hoping some here is using rewrites and would notice something in my
>provided code.

All good things come to those who wait ;-). I re-read the beginning of the thread but it's
not quite clear what you're trying to do -- if this is just a portion of your rewrite requirements,
or the only requirement.

>Also, I keep "services" open the background restart Couch after nearly
>every change. When you change one of the ini's, you have to.
>Thanks again for your help :-)

Hey Mark,

For your example you don't need rewrites, so let's get a simple solution in place first &
work from there.

Also, if you update couchdb settings via futon or the terminal, it Does The Right Thing with
Erlang Magic, and won't need a restart. e.g.:

curl  -XPUT http://admin:passwd@localhost:5984/_config/vhosts/methods --data-binary '"GET,

or similar does the trick.

## local.ini

feedme =  /feedme/site/index.html

Obviously feedme exists in /etc/hosts or dns already, and /feedme/ is the couchdb, /site/
is a document (not a design doc, but it could be), and /index.html is an attachment within
that doc. This means a normal couchdb user can serve an entire html site/app from a single
document, so long as vhosts are set up. IMO this is amazing.

### check that vhost is active

GET /_config/vhosts HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Authorization: Basic YWRtaW46cGFzc3dk
Content-Type: application/json; charset=utf-8
Host: localhost:5984
User-Agent: HTTPie/0.8.0-dev

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 127
Content-Type: application/json
Date: Tue, 08 Oct 2013 18:09:51 GMT
Server: CouchDB/1.5.0+build. (Erlang OTP/R16B02)

    "feedme": "/feedme/site/index.html",
    "testy": "/testy/site/index.html"

## upload a doc + attachment

I'm cheating slightly here by using a new doc and avoiding needing to pass the old rev in,
that's an Excercise for the Reader. I use the excellent python-based tool,
but you can do this with futon or whatever easily.

http put $COUCH/feedme/site/index.html content-type:'text/html; charset=utf-8' < index.html

## check that it all works

http get http://feedme:5984/                                          
GET / HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Type: application/json; charset=utf-8
Host: feedme:5984
User-Agent: HTTPie/0.8.0-dev

HTTP/1.1 200 OK
Accept-Ranges: none
Cache-Control: must-revalidate
Content-Encoding: gzip
Content-Length: 189
Content-MD5: Vfjf6/NxkRUmfgCLdb1Uvw==
Content-Type: text/html; charset=utf-8
Date: Tue, 08 Oct 2013 18:10:44 GMT
ETag: "Vfjf6/NxkRUmfgCLdb1Uvw=="
Server: CouchDB/1.5.0+build. (Erlang OTP/R16B02)

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
  vhosts in your couch

Is this sufficient, or do you have a more complex situation that needs rewrites?


View raw message